can't insert xml dml expression as a string
- by 81967
Here is the code below that would explain you the problem...
I create a table below with an xml column and declare a variable, initialize it and Insert the Value into the xml column,
create table CustomerInfo
(XmlConfigInfo xml)
declare @StrTemp nvarchar(2000)
set @StrTemp = '<Test></Test>'
insert into [CustomerInfo](XmlConfigInfo)
values (@StrTemp)
Then comes the part of the question,, if I write this...
update [CustomerInfo] set XmlConfigInfo.modify('insert <Info></Info> into (//Test)[1]')
-- Works Fine!!!
but when I try this,
set @StrTemp = 'insert <Info></Info> into (//Test)[1]'
update [CustomerInfo] set XmlConfigInfo.modify(@StrTemp)
-- Doesn't Work!!!
and throws an error
The argument 1 of the xml data type method "modify" must be a string literal.
is there a way around for this one?
I tried this, but it is not working :(