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.
| 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 FNow 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 MWhat 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' endfrom tablename-------------------------------------------------------------- |
 |
|
|
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 |
 |
|
|
|
|
|