eZeeNow.com

it's your's

How to read xml data in sql server using select clause?

We can read the xml data using select clause.

DECLARE @xml XML = '<colors> 
<color><value>black</value><code>#fff</code></color>
<color><value>white</value><code>#000</code></color>
<color><value>gray</value><code>#coco</code></color>
</colors>'

SELECT doc.col.value('value[1]', 'nvarchar(4)')
,doc.col.value('code[1]', 'nvarchar(4)')
FROM @xml.nodes('colors/color') doc(col)

Loading