Solved

How to replace the value using update statement?

Posted on 2010-08-12
3
461 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

932 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

13 Experts available now in Live!

Get 1:1 Help Now