T-SQL XML Query, how to separate matching nodes into individual rows? Part II

lRamonab

New Member
This question follows up this great answer: T-SQL XML Query, how to seperate matching nodes into individual rows?What if the values where:\[code\] <child> <name>Fred</name> <sname>Flintstone</name> </child> <child> <name>Bill</name> <sname>Gates</name> </child>\[/code\]And I wanted the output to be like:\[code\]FredFlintstoneBillGates\[/code\]Or even better, this:\[code\]name: Fredsname: Flintstonename: Billsname: Gates\[/code\](all in one column)-->Since I can't answer my own question for the next 3 hours, I'll edit my question as suggested by stackoverflow. Here's my answer to my own question:I've figured it out! :-) So I'm obliged to share my own solution. Here it is:\[code\]SELECT distinct childs.value('fn:local-name(.)', 'nvarchar(50)') + '=' + childs.value('(text())[1]', 'varchar(50)') as ChildrenFROM #t CROSS APPLY data.nodes('//parent/child/*') AS Children(childs) \[/code\]Thanks anyone for having a look at my question!
 
Back
Top