Using REPLACE in an UPDATE statement

By | November 5, 2017

How to use a REPLACE function in SQL UPDATE statement

Suppose you have a following ‘MasterData’ table in SQL,
Using REPLACE in an UPDATE statement

Using REPLACE in an UPDATE statement

And you want to replace a ‘!!’ by ‘{{‘ and ‘||‘ by ‘}}‘ in data column of table. How would you do it.

=> You can do it by using Replace function in an Update statement of SQL Server as below,

UPDATE dbo.MasterData
SET Value = REPLACE(REPLACE(Data, '!!', '{{'),'||','}}')
WHERE ID = 1

Inner Replace function is used for replacing ‘!!’ characters and outer replace function is used to replace  ‘||’.

Leave a Reply

Your email address will not be published. Required fields are marked *