• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

How to replace the value using update statement?

I have table having 2 columns name and sex like this.
Name    sex
A            M
B            F
C            M
D            F

From the above table I have to change all M values to F and F values to M using a single update statement.
Senthil B
Senthil B
2 Solutions
Guy Hengel [angelIII / a3]Billing EngineerCommented:
update yourtable  set sex = case when sex = 'M' then 'F' else 'M' endwhere sex in ('M', 'F')
James MurrellProduct SpecialistCommented:
Something like should help
update table
set sex = case when sex = 'M' then 'F' else 'M' end
where sex in ('M', 'F')

Senthil BAuthor Commented:
Both are correct solutions
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.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now