As in the header, I am trying to parameterize XPath for the modify () method for an XML data column in SQL Server, but in some problems.
So far I:
DECLARE @newVal varchar(50)
DECLARE @xmlQuery varchar(50)
SELECT @newVal = 'features'
SELECT @xmlQuery = 'settings/resources/type/text()'
UPDATE [dbo].[Users]
SET [SettingsXml].modify('
replace value of (sql:variable("@xmlQuery"))[1]
with sql:variable("@newVal")')
WHERE UserId = 1
with the following XML structure:
<settings>
...
<resources>
<type> ... </type>
...
</resources>
...
</settings>
which then generates this error:
XQuery [dbo.Users.NewSettingsXml.modify()]: The target of 'replace' must be at most one node, found 'xs:string ?'
Now I understand that the change method should not take a string as a path, but is there a way to accomplish this without using dynamic SQL?
Oh, by the way, I use SQL Server 2008 Standard 64-bit, but any queries that I write should be compatible with the 2005 standard.
Thank!
Chris source
share