using a xpath variable in a replace xquery, getting an error
- From: "JCollum" <jcollum@xxxxxxxxx>
- Date: 3 Nov 2006 16:02:20 -0800
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
.
- Follow-Ups:
- Prev by Date: Re: Combining XML Files using SSIS or T-SQL etc.
- Next by Date: Re: using a xpath variable in a replace xquery, getting an error
- Previous by thread: Re: Combining XML Files using SSIS or T-SQL etc.
- Next by thread: Re: using a xpath variable in a replace xquery, getting an error
- Index(es):
Loading