rebecca rebecca -4 years ago 76
SQL Question

Removing Multiple words in a string

I'm not trying to replace any words, I'm simply trying to remove specific words from the table without eliminating the entire string.
I tried this:

replace ([CRIDGI], 'inactive','') AS [CRID],


and it worked, but I need to add more words than just inactive

Answer Source

You can do this using nested replaces:

select replace(replace([CRIDGI], 'inactive', ''), 'active', '') AS [CRID]

Alas, SQL in general -- and most databases -- have pretty lousy string manipulation capabilities. It is hard to do better than the nested replace, although your database might have some functionality that would help (such as Oracle and Postgres).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download