0

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

<Record 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.

1
  • 2
    What do you want to query from that XML document?? What do you want to extract from it?? Commented Jan 18, 2011 at 13:18

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.