How to replace a string in a SQL Server Table Column

Viewed 854992

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?

10 Answers

It's this easy:

update my_table
set path = replace(path, 'oldstring', 'newstring')
UPDATE [table]
SET [column] = REPLACE([column], '/foo/', '/bar/')

you need to replace path with the help of replace function.

update table_name set column_name = replace(column_name, 'oldstring', 'newstring')

here column_name refers to that column which you want to change.

Hope it will work.

Related