开发者

SQL Server 2008: how to concatenate values in statement "replace value of"

开发者 https://www.devze.com 2023-03-22 20:40 出处:网络
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>\')

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消