Mohi Mohi - 3 months ago 8
SQL Question

SQL Server : how to update with string replace

How can I update some of columns:

UPDATE Product
SET Title = REPLACE(Title , 'mn%', 'za%')
WHERE (Title LIKE N'mn%')


Consider data of one column is
mnfmnd
and must be changed to
zafmnd

Answer

I would be inclined to use stuff() for this purpose:

update product
    set title = stuff(title, 1, 2, 'za')
    where title like 'mn%';