views:

24

answers:

1

I have a table:

declare @Table table (XmlPart xml, Cnt int)

the XmlPart is of the following form:

<Group count="0" />

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

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?

+3  A: 

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...

See the MSDN Docs on sql:column XQuery function.

marc_s
Thanks! Details rock :-)
Tim