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
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
ASKER
Thanks for the reply but i need them in select statement
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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;
UPDATE dbo.Schools SET SchoolType = 'Non-Denom' WHERE SchoolType = 'N'