T-SQL XML Query, how to seperate matching nodes into individual rows?

Posted by FlySwat on Stack Overflow See other posts from Stack Overflow or by FlySwat
Published on 2010-04-08T00:57:28Z Indexed on 2010/04/08 1:03 UTC
Read the original article Hit count: 573

Filed under:
|
|

I have a table that has a column full of XML like:

<parent>
   <child>
      <name>Sally</name>
   </child>
   <child>
      <name>Bobby</name>
   </child>
</parent>

I'm trying to extract all of the names of the children into seperate rows. My desired resultset would look like:

   Sally
   Bobby

However, if I do something like:

SELECT data.query('data(//parents/child/name)') FROM stuff

I get back a single row that looks like

Sally Bobby

What am I doing wrong with the XPath?

© Stack Overflow or respective owner

Related posts about xpath

Related posts about t-sql