The blog has moved to the new site F10Debug.com

Thursday, October 5, 2017

Using Replace in Update statement SQL

Using Replace in Update statement SQL

Suppose you have following table 'MasterData' table in SQL,


You want to replace '!!' by '{{' and '||' by '}}' in data column of table. How would you do it.

=> You can do it by using Replace function in 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  '||'.


No comments:

Post a Comment