Update and Replace Field Value with New Value

We can use SQL to replace the value in field with a new value.

There’s no need to search for those rows affecting, downloading each in turn, making the amendment and finally making the update.

For the update of the given field in the table we can use one SQL statement, changing all matching entries.

Here’s the general format of the search and replace:

UPDATE dbo.TableName
SET Field = REPLACE(Field, CurrentString, NewString)

So considering a spelling error, or perhaps a change of product name, we wish to update the product details table:

UPDATE dbo.product
SET details = REPLACE(details, 'appls', 'apples')

Note, the searched for string doesn’t have percentage characters. The search is a true search, not an SQL like.

An SQL like would be used as

SELECT * FROM details like ‘%apple%’