July 6, 2010 at 7:21 am
declare @xml_complete xml, @xml_child_element xml
set @xml_complete = '<U id = "1">
<N id = "2"/>
</U>'
i want to set @xml_child_element variable to be equal to the nested element '<N id = "2"/>'
i know how to get the node values but i just need the nested xml.
Thanks for all help.
Jules,
July 6, 2010 at 3:21 pm
How about
SELECT @xml_child_element = @xml_complete.query('/U/N[1]')
July 7, 2010 at 12:36 am
July 7, 2010 at 11:41 am
There might be an easier way to do it but here's a solution that first extract the value and assign "P" as an table alias and "id" as the column name and change it back to the original xml format using FOR XML AUTO.
SELECT c.value('@id[1]','varchar(30)') AS id
FROM @xml_complete.nodes('U/N') P(c)
FOR XML AUTO
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply