?
Solved

How to replace the value using update statement?

Posted on 2010-08-12
3
Medium Priority
?
466 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 750 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 750 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

741 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