I have three column in my table with one column of XML type. I want to show different nodes of the XML data in different rows. Like,
Col1 Col2 Col3
12 ABC <Interactions><interaction id='2' name='A'/><interaction id='3' name='B'/></Interactions>
How to show different interaction in different rows? like,
Row1 : 12 ABC 2 A
Row2 : 12 ABC 3 B
Thanks! Ank
Try this
SELECT
A.Col1
,A.Col2
,Split.interaction.value('@id', 'INT') AS [ID]
,Split.interaction.value('@name', 'VARCHAR(10)') AS [Name]
FROM
(
SELECT Col1, Col2, Col3 FROM #Tablexml
) AS A CROSS APPLY Col3.nodes ('/Interactions/interaction') AS Split(interaction);
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With