Thursday, February 25, 2016

UPDATE part of a string in SQL Server using REPLACE

I've got a table with two columns, ID and Value. I want to change a part of some strings in the second column.
Example of Table:
ID            Value
---------------------------------
1             c:\temp\xyz\abc\111
2             c:\temp\xyz\abc\222
3             c:\temp\xyz\abc\333
4             c:\temp\xyz\abc\444
Now the xyz\ in the Value string is not needed. 
For UPDATE and REPLACE the same, use below SQL query :
UPDATE dbo.xxx
SET Value = REPLACE(Value, 'xyz\', '')
WHERE ID <=4
you can read more about REPLACE here .

No comments:

Post a Comment