Click here to Skip to main content
15,891,880 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For example i have a column named as gender and records are male and female.
so i want to replace male as M and female as F.
Please help me out
Posted

SQL
declare @temp table(gender nvarchar(50) null)
insert into @temp (gender)
select 'Male'
union all
select 'FeMale'
union all
select 'FeMale'
union all
select 'Male'
union all
select 'FeMale'

select * from @temp

update @temp set gender=(case (gender) when 'Male' then 'M' else 'F' end) from @temp

select * from @temp
 
Share this answer
 
Comments
Hitesh Varde 29-Apr-14 5:02am    
you not need to take 'from @temp' at the end in your query.
Devendra Singh shekhawat 29-Apr-14 5:38am    
it's just a example
Hitesh Varde 29-Apr-14 5:53am    
I just pointed if you want to update.
Hello,

Please try below query, Let me know if it helps.
SQL
UPDATE [YourTableName] SET GENDER=(CASE WHEN GENDER = 'Male' THEN 'M' ELSE 'F' END)

Thanks,
Hitesh Varde
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900