SQL XML, select from xml using nodes() function
By admin - Last updated: Thursday, October 1, 2009 - Save & Share - Leave a Comment
Very handy function that helps me move small data around.
DECLARE @myXml AS XML
SET @myXml =
‘<ArrayOfProduct>
<Product id="1">
<Description>test1</Description>
</Product>
<Product id="2">
<Description>test2</Description>
</Product>
</ArrayOfProduct>
‘
SELECT
T.c.VALUE(‘@id[1]‘, ‘int’) AS [id]
, T.c.VALUE(‘Description[1]‘, ‘nvarchar(max)’) AS [description]
FROM @myXml.nodes(‘/ArrayOfProduct/Product’) AS T(c)
(you might need to )
