views:

431

answers:

3

Trying the following code. But getting 'The argument 1 of the xml data type method "modify" must be a string literal' error. searched alot but cant find any solution for this problem

SET @Path = '/@ParentNodeName/@NodeName/child::*'
SET @x.modify('insert attribute status {sql:variable("@status")}
               as first into (' + @Path + ')[1]')
+1  A: 

The problem isn't the sql:variable with the value you're trying to insert - it's the way you include the XPath into your modify statement. You cannot string together that command - you need to use a literal:

So you need to use:

SET @x.modify('insert attribute status {sql:variable("@status")}
               as first into (/Parent/Node/)[1]')

Then it works just fine.

marc_s
Any possiblity of using a dynamic path...instead of giving the absolute path
sam
@Sam: no, I'm afraid, not - at least I haven't ever been able to get it to work :-( With SQL Server 2008 you can specify a sql:variable for the value to insert - but not for the path where to insert to
marc_s
A: 

CAn I use this in the following way

  SET @x.modify('insert attribute status {sql:variable("@status")} 
           as first into (/@ParentNodeName/@NodeName/child::*)[1]')

PLz suggest

sam
A: 

@marc: Do you have any idea if we try to do this by defining the xsd of an existing xml doc and then having dynamic path

sam