UPDATE and REPLACE part of a string
You don't need wildcards in the REPLACE
- it just finds the string you enter for the second argument, so the following should work:
UPDATE dbo.xxxSET Value = REPLACE(Value, '123', '')WHERE ID <=4
If the column to replace is type text
or ntext
you need to cast it to nvarchar
UPDATE dbo.xxxSET Value = REPLACE(CAST(Value as nVarchar(4000)), '123', '')WHERE ID <=4
Try to remove %
chars as below
UPDATE dbo.xxxSET Value = REPLACE(Value, '123', '')WHERE ID <=4
To make the query run faster in big tables where not every line needs to be updated, you can also choose to only update rows that will be modified:
UPDATE dbo.xxxSET Value = REPLACE(Value, '123', '')WHERE ID <= 4AND Value LIKE '%123%'