Link to home
Start Free TrialLog in
Avatar of mmalik15
mmalik15

asked on

how to do multiple Replace in one column in sql statement

I have a column in the database called SchoolType with the possible values N and D. I want to repalce N with Non-Denom and D with Denom. I have tried something like this in sql

select distinct replace (replace (SchoolType,'D', 'Denom') ,'N','Non-Denom') from dbo.Schools where Schooltype is not null

the results lI get are like

DeNon-Denomom
Non-Denom

how could we achive the desired results? as below

Denom
Non-Denom
Avatar of Om Prakash
Om Prakash
Flag of India image

UPDATE dbo.Schools  SET SchoolType = 'Denom'  WHERE SchoolType = 'D'
UPDATE dbo.Schools  SET SchoolType = 'Non-Denom'  WHERE SchoolType = 'N'
Avatar of mmalik15
mmalik15

ASKER

Thanks for the reply but i need them in select statement
ASKER CERTIFIED SOLUTION
Avatar of Om Prakash
Om Prakash
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent
Please try this


if SchoolType contains only 'N' and 'D', then you can proceed with (1) query otherwise (2)

1) select if(schooltype='D','Denom','Non-Denom') from tablename

2) select if(schooltype='D','Denom',if(schooltype = 'N','Non-Denom',schooltype)) from tablename;

Open in new window