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
Post a Comment