Replace a word in SQL in comma separated list -
i have varchar column in sql table containing words separated comma like:
col1 man,woman,cat dog,man,cat dog,cat,woman,man and need replace word another, let's replace "man" "boy"
but i'd need avoid situation when "man" replaced part of word - "woman" becomes "woboy"
how in sql?
update table1 set col1=??? ???
okay, i'm sure there better ways, works (for sql server):
update table1 set col1 = substring(replace(',' + col1 + ',',',man,',',boy,'),2, len(replace(',' + col1 + ',',',man,',',boy,'))-2) ',' + col1 + ',' '%,man,%';
Comments
Post a Comment