Click here to Skip to main content
15,911,707 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i created one table with cols name and gender. i inseted values.now i want inerchange values in gender col as M=F,F=M

id gender
1 M
2 F
3 M
4 F
5 M
6 F

AFTER CHANGE OUT PUT USE SINGLE QUERY
id gender
1 F
2 M
3 F
4 M
5 F
6 M
Posted
Comments
André Kraak 6-Oct-11 4:05am    
Repost of: http://www.codeproject.com/Questions/264735/how-to-write-single-query-chage-data
Please do not repost your question; it will not help get it answered any quicker.
It may even work against you as people do not like this pushy behaviour.
Look at your original question and see if you can make it any clearer and respond to any inquiries made; this should make the question more appealing.

If you intended to update the original question please move the content of this solution to the original one. You can change the original question by using the Improve question button.

Please remove this repost. Thank you.

1 solution

You can use the CASE WHEN construct to do the same: http://msdn.microsoft.com/en-us/library/ms181765(v=SQL.90).aspx[^].

An example:
SQL
UPDATE dbo.GenderTable
SET gender = CASE
                 WHEN 'F' THEN 'M'
                 WHEN 'M' THEN 'F'
             END   


This works for SQL-Server 2005 & 2008.


Regards,
—MRB
 
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