How to replace a string in a SQL Server Table Column

Iralda Mitro picture Iralda Mitro · May 2, 2009 · Viewed 800.3k times · Source

I have a table (SQL Sever) which references paths (UNC or otherwise), but now the path is going to change.

In the path column, I have many records and I need to change just a portion of the path, but not the entire path. And I need to change the same string to the new one, in every record.

How can I do this with a simple update?

Answer

cjk picture cjk · May 2, 2009

It's this easy:

update my_table
set path = replace(path, 'oldstring', 'newstring')