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

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -