Only replace string in sql when not adjacent to other characters -



Only replace string in sql when not adjacent to other characters -

i'm using mssql 2008 replace values in columns. current query is:

update table set name = replace(name, 'old', 'new')

i know if possible replace 'old' 'new' when 'old' not adjacent other characters. is: when occurs 'old' ensure e.g. 'bold' not become 'bnew'

currently i'm retrieving results via jdbc, splitting string @ delimiter (,) , checking if string equals'old'. if want replace 'new'. takes long time retrieve results , send them back, if possible sending sql-statement containg 'old' & 'new' great!

records should replaced:

'old , blabla blabla, bla' 'blabla, old, blabla' 'blabla, bla old, blabla' 'blabla, blabla, old' 'blabla, bla old bla'

records shouldn't replaced:

'blaold, blabla' 'blabla, oldbla'

use spaces in clauses.

update [yourtable] set name = replace(name, ' old ', 'new') name = ' old '

sql replace

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -