Solved

How to replace the value using update statement?

Posted on 2010-08-12
3
460 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:senthilkumarsb
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 33427092
update yourtable  set sex = case when sex = 'M' then 'F' else 'M' endwhere sex in ('M', 'F')
0
 
LVL 31

Assisted Solution

by:James Murrell
James Murrell earned 250 total points
ID: 33427118
Something like should help
update table
set sex = case when sex = 'M' then 'F' else 'M' end
where sex in ('M', 'F')

James
0
 
LVL 4

Author Closing Comment

by:senthilkumarsb
ID: 33427334
Both are correct solutions
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now