I'm using MSSQL 2008 to replace the values in certain columns. My current query is:
UPDATE table
SET name = replace(name, 'old', 'new')
I would like to know if it is possible to only replace 'old' by 'new' when 'old' is not adjacent to other characters. That is: only when it actually occurs as 'old' This would ensure that e.g. 'bold' does not become 'bnew'
Currently I'm retrieving results via JDBC, splitting the string at the delimiter (,) and then checking if the string equals'old'. If so I want to replace with 'new'. It takes a long time to retrieve all the results and send them back, so if this is possible by only sending an SQL-statement containg 'old' & 'new' that would be great!
Records where it should be replaced:
Records where it shouldn't be replaced:
Use spaces in your clauses.
UPDATE [YourTable] SET name = replace(name, ' old ', 'new') WHERE name = ' old '
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With