0

I'm trying to extract a chunk of XML (ie the whole xml of a node, not just content) using an xpath query in SQL. I can extract a single content field but am not sure how to do the above.

Say the xml is as follows

<head>
    <instance>
        <tag1>
              <tag2>data</tag2>
              <tag3>data</tag3> 
        </tag1> 
    </instance> 
</head>

I would like to extract all of the xml inside tag1, and was hoping something like this would work in a SQL query:

Table.value('(/head/instance/tag1)[1]', 'varchar(max)') as "col"

Any help would be great.

Thanks

1
  • @user270370: This is not asking for an XPath expression but for no standar SQL type conversion Commented Jan 13, 2011 at 14:13

1 Answer 1

2

this should work:

Select Cast(Table.xmlcolumnname.query('/head/instance/tag1') as varchar(max)) 'col';

(its not checked! may contain typo..)

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.