Thursday, May 14, 2009

Read XML nodes in SQL


DECLARE @htc xml

SET @htc = '
<boatGroup>
<boat>
<boatId>1CDA141</boatId>
</boat>
</boatGroup>'


SELECT O.boat.value('(boatId)[1]','nvarchar(max)') AS BoatID
FROM @htc.nodes('/boatGroup/boat') AS O(boat)




Reads all the 'boatId' elements within the 'boat' node. Element names are case sensitive.

No comments: