UPDATE SQL statement

Hello friends,

I want to update all F (female) and M (Male) values (change all F values to M and vice versa) as per below table.

Id >> Name >> Sex >> Salary
1 >> A >> M >> 6000
2 >> B >> F >> 3500
3 >> C >> M >> 8500
4 >> D >> F >> 600

How should I write the query to update the values?
Ajit KhodkeDigital Marketing ProfessionalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
Not sure what you mean here.  If the question is 'how do I flip flop values in a column', then give the below a whirl...
UPDATE YourTable

Open in new window

If there's any other logic, then please spell it out in greater detail.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bbaoIT ConsultantCommented:

UPDATE your_table
SET sex = IIF(sex = 'M', 'F', IIF(sex = 'F', 'M', 'F'))
Jim HornMicrosoft SQL Server Data DudeCommented:
IF is 2012 and above, and I wasn't sure what version of SQL we're on here, so I gave a CASE answer.

Ajit Khodke - Let us know if these solutions met your needs.
Ajit KhodkeDigital Marketing ProfessionalAuthor Commented:
Thanks  Jim and bbao for great solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.