sqlreplacesql-server-2016

SQL Replace multiple different characters in string


I need to replace multiple characters in a string. The result can't contain any '&' or any commas.

I currently have:

REPLACE(T2.[ShipToCode],'&','and')

Which converts & to and, but how do you put multiple values in one line?


Solution

  • You just need to daisy-chain them:

    REPLACE(REPLACE(T2.[ShipToCode], '&', 'and'), ',', '')