SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Other Forums
 Other Topics
 Please help me this query very urgent please!!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 03/07/2006 :  08:18:16  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
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

USA
15676 Posts

Posted - 03/07/2006 :  08:18:55  Show Profile  Visit robvolk's Homepage  Reply with Quote
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)

Singapore
17650 Posts

Posted - 03/07/2006 :  08:25:16  Show Profile  Reply with Quote
What have you already tried ?

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


Go to Top of Page

mr_mist
Grunnio

United Kingdom
1870 Posts

Posted - 03/07/2006 :  08:26:33  Show Profile  Visit mr_mist's Homepage  Reply with Quote
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

USA
71 Posts

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

~Travis

Edited by - twhelan1 on 03/07/2006 09:37:27
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
7020 Posts

Posted - 03/07/2006 :  11:26:44  Show Profile  Reply with Quote
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

Edited by - Michael Valentine Jones on 03/07/2006 11:30:17
Go to Top of Page

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 03/07/2006 :  11:41:04  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
Perhaps he works for a doctor that performs sex changes?
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

USA
4137 Posts

Posted - 03/07/2006 :  12:37:59  Show Profile  Visit graz's Homepage  Reply with Quote
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)

USA
7020 Posts

Posted - 03/07/2006 :  13:58:58  Show Profile  Reply with Quote
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

Sweden
30265 Posts

Posted - 11/10/2006 :  00:45:35  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
22761 Posts

Posted - 11/10/2006 :  10:51:44  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote


Madhivanan

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

General Anders
Starting Member

3 Posts

Posted - 07/23/2007 :  19:40:53  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000