Jul 19, 2010 #1 peac3 Technical User Joined Jan 17, 2009 Messages 226 Location AU Hi guys, I am trying to update the single column which contains many words and want to update the word '%main%' to become '%optional%' the table contains thousand of records. Any idea how to do this? database : MSSQL 2005 Thanks in advance guys,
Hi guys, I am trying to update the single column which contains many words and want to update the word '%main%' to become '%optional%' the table contains thousand of records. Any idea how to do this? database : MSSQL 2005 Thanks in advance guys,
Jul 19, 2010 #2 markros Programmer Joined May 21, 2007 Messages 3,150 Location US Try Code: update myTable set ColWords = rtrim(ltrim(replace (' ' + ColWords + ' ',' main ',' optional '))) where ' ' + ColWords + ' ' LIKE '% main %' Assuming that words are separated by spaces and you only want to update whole words. PluralSight Learning Library Upvote 0 Downvote
Try Code: update myTable set ColWords = rtrim(ltrim(replace (' ' + ColWords + ' ',' main ',' optional '))) where ' ' + ColWords + ' ' LIKE '% main %' Assuming that words are separated by spaces and you only want to update whole words. PluralSight Learning Library
Jul 20, 2010 Thread starter #3 peac3 Technical User Joined Jan 17, 2009 Messages 226 Location AU Hi makros, Unfortunately, the columns words are not always the same, Code: ie main product main industrial selected main code would like become: optional product optional industrial selected optional code Thanks, Upvote 0 Downvote
Hi makros, Unfortunately, the columns words are not always the same, Code: ie main product main industrial selected main code would like become: optional product optional industrial selected optional code Thanks,
Jul 20, 2010 #4 markros Programmer Joined May 21, 2007 Messages 3,150 Location US Did you try my solution? First to verify it, use SELECT instead of UPDATE, e.g. Code: select myWordColumn, replace(...) from myTable where ' ' + myWordColumn + ' ' like '% main %' PluralSight Learning Library Upvote 0 Downvote
Did you try my solution? First to verify it, use SELECT instead of UPDATE, e.g. Code: select myWordColumn, replace(...) from myTable where ' ' + myWordColumn + ' ' like '% main %' PluralSight Learning Library