Translate

Thursday, March 27, 2014

XQuery modify attribute

declare
@transferID uniqueidentifier
,@transferIDchar nvarchar(37)
,@xmlString nvarchar(max)
,@hdoc int
,@xmlDoc xml
,@idx int;
declare @tmpTable table (id uniqueidentifier, data xml);

select @xmlString = N'';

select @transferID = NEWID();
select @transferIDchar = CONVERT(nvarchar(37), @transferID);

insert @tmpTable (id, data)
values (@transferID, @xmlString);

update @tmpTable
set data.modify('replace value of (/Transfer/@ID)[1] with sql:variable("@transferID")');

select 
*
from @tmpTable;