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
 Other Forums
 Other Topics
 Please help me this query very urgent please!!

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-03-07 : 08:18:16
Anand writes "Hi all please help me in my query one recruiter ask me how to do this. here it is what they did ask me:-------
there is one table in that table two columns name and gender and the things is that suppose the table is like that

Name Gender
Ken M
kate F
Lucy F
Brian M
so please what we have to do write only one single query which we will select all the male from the databse and update them to female and all female to Mail but this should be only in one single query.
Not a two query at all ok
please help i did use select case but no luck!!!
:(
please reply to me onephpguy@yahoo.com
Thanks to whole SQL team."

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-03-07 : 08:18:55
Before posting any answers, please refer to this thread:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62702
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-07 : 08:25:16
What have you already tried ?

----------------------------------
'KH'


Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2006-03-07 : 08:26:33
Before I can provide an answer to this question, I need to know which washing powder Lucy uses.

-------
Moo. :)
Go to Top of Page

twhelan1
Yak Posting Veteran

71 Posts

Posted - 2006-03-07 : 09:29:26
Must have been a job interview with a Swiss company? Nevermind... bad joke.

~Travis
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-03-07 : 11:26:44
This should do the job.

update Mytable
set
Gender =
case
when name in ('Ken','Brian')
then 'F'
when name in ('Kate','Lucy')
then 'Mail'
else Gender
end




CODO ERGO SUM
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-03-07 : 11:41:04
Perhaps he works for a doctor that performs sex changes?
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2006-03-07 : 12:37:59
quote:
Originally posted by Michael Valentine Jones

This should do the job.

update Mytable
set
Gender =
case
when name in ('Ken','Brian')
then 'F'
when name in ('Kate','Lucy')
then 'Mail'
else Gender
end




CODO ERGO SUM



I really hope someone submits this in an interview.

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-03-07 : 13:58:58
quote:
Originally posted by graz
...I really hope someone submits this in an interview...


I believe it meets all stated requirements.





CODO ERGO SUM
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-10 : 00:45:35
This can be fun!
update Mytable
set
Gender =
case
when len(name) % 2 = 0
then 'M'
else 'F'
end


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-10 : 10:51:44


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

General Anders
Starting Member

3 Posts

Posted - 2007-07-23 : 19:40:53
It sounds like the professor isn't asking you to modify the database but just to return the inverse of M/F? If the datatypes are set properly (restricts to M or F) could we just use the NOT function?

select name, NOT gender
Go to Top of Page
   

- Advertisement -