October 5, 2012 at 8:33 pm
Hi i have a small doubt
DECLARE @XML XML='<ROOT>
<ITEMS PID="0" FN="DEFAULT " LN="DEFAULT" />
<ITEMS PID="1" FN="HARISH" LN="SINGH" />
</ROOT>'
select @XML
how to add additional values GID,TID to the existing xml
i want output like this
<ROOT>
<ITEMS PID="0" FN="Default " LN="Default" GID="1" TID="42" />
<ITEMS PID="1" FN="HARISH" LN="SINGH" GID="1" TID="42" />
</ROOT>
October 5, 2012 at 9:47 pm
Just and example:
declare @var int = 40
DECLARE @XML XML='<ROOT>
<ITEMS PID="0" FN="DEFAULT " LN="DEFAULT" />
<ITEMS PID="1" FN="HARISH" LN="SINGH" />
</ROOT>'
SELECT @XML
SET @XML.modify('
insert attribute GID {sql:variable("@var") }
into (/ROOT/ITEMS)[1] ')
SELECT @XML
Edited : check out the msdn for inserting xml nodes, attributes and elements..
http://msdn.microsoft.com/en-us/library/ms175466.aspx
~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one :ermm:
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply