Nikhil Agrawal Nikhil Agrawal - 2 years ago 102
SQL Question

Replace multiple characters in SQL

I have a problem where I want to replace characters

I am using

function but that is not giving desired output.

Values of column table_value needs to replaced with their fill names like

E - Email

P - Phone

M - Meeting

enter image description here

I am using this query

select table_value,
replace(replace(replace(table_value, 'M', 'MEETING'), 'E', 'EMAIL'), 'P', 'PHONE') required_value
from foobar

so second
row should be
and so on.

What should I do so that required value is correct?

Answer Source

The below will work (even it's not a smart solution).

    replace(replace(replace(replace(table_value, 'M', 'MXXTING'), 'E', 'XMAIL'), 'P', 'PHONX'), 'X', 'E') required_value 
from foobar
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download