0

I am trying to update an existing XML column value in SQL Server.

declare @xml xml;
select @xml = 
'<items xmlns:dt="urn:schemas-microsoft-com:datatypes">
<item dt:dt="string">Item1<item>
</items>';
set @xml.modify('insert <item dt:dt="string">Item2</item> into (/items)[1]');

This throws the error: XQuery [modify()]: The namespace prefix 'dt' has not been defined

How can I get the namespace in to the modify?

workvact
  • 613
  • 2
  • 8
  • 14

1 Answers1

2
declare @xml xml;
select @xml = 
'<items xmlns:dt="urn:schemas-microsoft-com:datatypes">
<item dt:dt="string">Item1</item>
</items>';
select @xml;

set @xml.modify('declare namespace dt="urn:schemas-microsoft-com:datatypes"; insert <item dt:dt="string">Item2</item> into (/items)[1]');

select @xml;
lptr
  • 1
  • 2
  • 6
  • 16