SQL Server 2008:修改xml,使用列值替换属性值

时间:2023-01-14 00:16:25

I have a table:

我有一张桌子:

declare @Table table (XmlPart xml, Cnt int)

the XmlPart is of the following form:

XmlPart具有以下形式:

<Group count="0" />

I would like to modify XmlPart by substituting it with value of Cnt column. That's what I try:

我想通过用Cnt列的值替换它来修改XmlPart。这就是我尝试的:

update @Table
set XmlPart.modify('replace value of (/Group/@count)[1] with sql:column(Cnt)')

But the parser doesn't understand me..

但解析器不理解我..

Is it possible to substitute an attribute (or node value) of an xml with table column?

是否可以用表列替换xml的属性(或节点值)?

1 个解决方案

#1


6  

You almost got it right :-)

你几乎把它弄好了:-)

update @Table
set XmlPart.modify('replace value of (/Group/@count)[1] with sql:column("Cnt")')

You need to put the column name in sql:column into double quotes...

您需要将sql:列中的列名称放入双引号中...

See the MSDN Docs on sql:column XQuery function.

请参阅sql:column XQuery函数上的MSDN Docs。

#1


6  

You almost got it right :-)

你几乎把它弄好了:-)

update @Table
set XmlPart.modify('replace value of (/Group/@count)[1] with sql:column("Cnt")')

You need to put the column name in sql:column into double quotes...

您需要将sql:列中的列名称放入双引号中...

See the MSDN Docs on sql:column XQuery function.

请参阅sql:column XQuery函数上的MSDN Docs。