Search code examples
sqlssms

Remove string from multiple rows SQL


I have a table that has "HQ created..." in 100+ rows. Instead of manually updating those rows I want to trim that part off.

I tried:

UPDATE Table SET Desc = LTRIM('HQ created') WHERE Desc LIKE '%HQ created%'

and that changed all 100+ rows to "HQ created" instead of cutting that part off.

(I also tried SET HADEDesc = RTRIM('HQ created'))

A replace will not work as outside of the "HQ created..." the names are different for example "HQ created Date" and "HQ created Time".


Solution

  • update table
    set desc = replace(Desc, 'HQ created' , '')
     WHERE Desc LIKE '%HQ created%'