Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Query regarding interchanging the data

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-29 : 10:33:25
Kiran writes "Suppose I have table name Student, which has 2 fields Name and
Sex.
For eg Name Sex
Kiran M
Ranjita F
Charls M
HArry M
MAdona F

Now I want to change the sex of the M to F and F to M in single query (if needed using subquery). The output should be
Name Sex
Kiran F
Ranjita M
Charls F
HArry F
MAdona M

What will be the query for it in SQL SERVER 7.0 or more, Access 97/2000?"

Nazim
A custom title

1408 Posts

Posted - 2002-04-29 : 10:38:13
select name, case sex when 'F' then 'M' else 'F' end
from tablename

--------------------------------------------------------------
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-04-29 : 19:17:29
And if you actually want to change the data in the table, you can use Nazim's CASE statement in an UPDATE statement like this:


UPDATE Person SET
Sex =
CASE Sex
WHEN 'M' THEN 'F'
ELSE 'M'
END


Go to Top of Page
   

- Advertisement -