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

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

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

create table #t (data xml)


insert #t values ('
<parent>
   <child>
      <name>Sally</name>
   </child>
   <child>
      <name>Bobby</name>
   </child>
</parent>
')


insert #t values ('
<parent>
   <child>
      <name>Fred</name>
   </child>
   <child>
      <name>Bill</name>
   </child>
</parent>
')


select C.* from #t 
cross apply (select name.value('name[1]', 'varchar(255)') as [Name] from data.nodes('//parent/child') as c(name)) as C

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results