tags:

views:

1016

answers:

2

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
A: 
update my_table
set xml_column = replace(xml_column, "old  value", "new value")
Avdi
"Argument data type xml is invalid for argument 1 of replace fuction"
Phil