开发者

can't insert xml dml expression as a string

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></Inf开发者_如何学运维o> 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 :(


AS it usually comes out, Dynamic SQL is something that has always come to my rescue :)

but much to my anxiety, considering t-sql is interpreted, why not make tsql more like a dynamic language itself, can any one suggest why such strong typing in t-sql?

here is the link that has a few options solutions regarding the problem,

Solution I used:

Execute sp_executesql @StrQuery

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜