Here is my test SQL:
declare @Table table (strField nvarchar(6), xmlField xml)开发者_JAVA技巧
insert into @Table values ('123456', '<root><Node value="node value"/></root>')
select * from @Table
Now what I'm trying to figure out is how to update value of XML field here and assign a new value to it that would be a concatenation of two pieces. Here is what I got so far:
update @Table
set xmlField.modify('replace value of (/root/Node/@value)[1]
with "new node value" + sql:column("strField")')
But this syntax is not good enough for SQL Server. I googled for solution but didn't find any good. I wonder if there is a way at all to do what I'm trying to?
How about concat("new node value", sql:column("strField"))
?
See the concat function (XQuery) from the SQL Server 2008 documentation.
Happy coding.
精彩评论