using a xpath variable in a replace xquery, getting an error



I'm trying to do a dynamic xpath in a query and the compiler isn't
allowing it. I'm getting a "The target of 'replace' must be at most
one node, found 'xs:string ?" error. Umm, yeah that's fine except I've
got that [1] on the end of the xpath. Seems to me that makes it one
node ya know?

So I'm stuck. I'm gonna investigate getting the nodes, ie
MyXml.nodes('/root/product/name') as NewTable(ProductName).

This looks like the compiler thinking that it's smarter than me. I doan
like eet.

--SQL Code:

declare @nodeCount int, @xpath nvarchar(100), @pr nvarchar(100),
@newVal nvarchar(100)

set @xpath = '/path1/elem1'

--xml-column.modify('replace value of xpath-expression with new-value')
sql:variable("@xpath")
UPDATE MyTable SET MyXml.modify(
'
replace value of (sql:variable("@xpath"))[1] --<-- Error here
with "someNewStuff"
')
where MyId = 2

--END CODE

.


Loading