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
mmalik15Asked:
Who is Participating?
 
Om PrakashConnect With a Mentor Commented:
TO SELECT
SELECT (CASE SchoolType WHEN 'D' THEN 'Denom' WHEN 'N' THEN 'Non-Denom' ELSE 'N/A' END) FROM SchoolType;
0
 
Om PrakashCommented:
UPDATE dbo.Schools  SET SchoolType = 'Denom'  WHERE SchoolType = 'D'
UPDATE dbo.Schools  SET SchoolType = 'Non-Denom'  WHERE SchoolType = 'N'
0
 
mmalik15Author Commented:
Thanks for the reply but i need them in select statement
0
 
mmalik15Author Commented:
Excellent
0
 
VishnukumarCommented:
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.