Denis
Denis

Reputation: 43

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

Here is my test SQL:

declare @Table table (strField nvarchar(6), xmlField xml)
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?

Upvotes: 2

Views: 1070

Answers (1)

user166390
user166390

Reputation:

How about concat("new node value", sql:column("strField"))?

See the concat function (XQuery) from the SQL Server 2008 documentation.

Happy coding.

Upvotes: 1

Related Questions