views:

37

answers:

1

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 :(

A: 

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

81967