I basically have an xml column, and I need to find and replace one tag value in each record.
+5
A:
To find a content in an XML column, look into the exist() method, as described in MSDN here.
SELECT * FROM Table
WHERE XMLColumn.exist('/Root/MyElement') = 1
...to replace, use the modify() method, as described here.
SET XMLColumn.modify('
replace value of (/Root/MyElement/text())[1]
with "new value"
')
..all assuming SqlServer 2005 or 2008. This is based on XPath, which you'll need to know.
Michael Petrotta
2008-10-05 03:29:42
A:
update my_table
set xml_column = replace(xml_column, "old value", "new value")
Avdi
2008-10-05 03:31:07
"Argument data type xml is invalid for argument 1 of replace fuction"
Phil
2010-07-28 13:33:51