开发者

XML data type and Sql server 2005

开发者 https://www.devze.com 2023-02-05 02:25 出处:网络
i have one table where one field type is xml and there data is saved in xml format. my xml is <Reco开发者_Go百科rd xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">

i have one table where one field type is xml and there data is saved in xml format. my xml is

<Reco开发者_Go百科rd xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <DELETED>
    <STOCK_CODE>111111</STOCK_CODE>
    <MakeID>GB00000001</MakeID>
    <ModelID>GB00000001</ModelID>
    <EngineSize />
    <YearMakeFrom>0</YearMakeFrom>
    <YearMakeTo>0</YearMakeTo>
    <Automatic>1</Automatic>
    <SemiAutomatic>1</SemiAutomatic>
    <Manual>0</Manual>
    <OtherInfo />
    <Status>UPDATED</Status>
  </DELETED>
</Record>

so please tell me how could i query the above xml document in sql server 2005. please help. thanks.


You're not saying what you're looking for exactly - so here's just a guess.

Assume you have a table full of rows, each row has a XML column XmlData which contains the above structure, and you want to get the Stock_Code and ModelID from that XML.

In that case, you'd use something like this:

SELECT 
    ID,
    XmlData.value('(/Record/DELETED/STOCK_CODE)[1]', 'BIGINT') AS 'StockCode',
    XmlData.value('(/Record/DELETED/ModelID)[1]', 'VARCHAR(25)') AS 'ModelID' 
FROM 
    dbo.YourTable
WHERE
    (some condition)

Is that what you're looking for?? If not: please clarify your question!

0

精彩评论

暂无评论...
验证码 换一张
取 消