Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

T-SQL query Expand / Collapse
Author
Message
Posted Thursday, May 1, 2008 8:42 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, May 4, 2009 4:44 AM
Points: 75, Visits: 8
Comments posted to this topic are about the item T-SQL query
Post #494010
Posted Thursday, May 1, 2008 8:46 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, January 8, 2014 2:49 PM
Points: 1,279, Visits: 2,203
Very tricky! I made a guess. Yes. Anything is possible.
Post #494011
Posted Friday, May 2, 2008 1:32 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 4:04 AM
Points: 1,865, Visits: 591
you could use a case statement:

where
case month(dob)
when 1 then 1
when 3 then 1
when 4 then 1
when 5 then 1
when 7 then 1
when 8 then 1
else 0 end = 1


Life: it twists and turns like a twisty turny thing
Post #494069
Posted Friday, May 2, 2008 1:33 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Today @ 5:19 AM
Points: 646, Visits: 1,854
Handy to know...I'm sure I'll be using that in my code very soon!
Post #494070
Posted Friday, May 2, 2008 1:36 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, July 2, 2014 1:09 AM
Points: 834, Visits: 329
That was a very nice question for a Friday morning.

Another solution would be:
datepart(m,dob) between 1 and 8
and datepart(m,dob) <> 2
and datepart(m,dob) <> 6

Though the single condition definitely beats this solution.
Post #494071
Posted Friday, May 2, 2008 2:12 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, July 8, 2014 8:02 AM
Points: 1,105, Visits: 298
Knut Boehnert (5/2/2008)
That was a very nice question for a Friday morning.

I'd have to disagree. I think these ones about working out pointless conditions to satisfy one off special cases that nobody will EVER use, are more about your ability (and level of interest) in working out what's different about those months than the others. As such, they have almost nothing to to with T-SQL (which was the 'Question Type') other than that they chose to write the solution in it. I imagine many people will simply guess yes (there's usually a way to do anything that starts with 'is there a way...') without really knowing why. I decided to be contrary and guessed no, based on the last (equally pointless) one of these being 'yes'.

-- Kev


-------------------------------
Oh no!
Post #494082
Posted Friday, May 2, 2008 4:46 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, July 17, 2014 10:36 PM
Points: 5,303, Visits: 1,378
Kevin Gill (5/2/2008)
Knut Boehnert (5/2/2008)
That was a very nice question for a Friday morning.

I'd have to disagree. I think these ones about working out pointless conditions to satisfy one off special cases that nobody will EVER use, are more about your ability (and level of interest) in working out what's different about those months than the others. As such, they have almost nothing to to with T-SQL (which was the 'Question Type') other than that they chose to write the solution in it. I imagine many people will simply guess yes (there's usually a way to do anything that starts with 'is there a way...') without really knowing why. I decided to be contrary and guessed no, based on the last (equally pointless) one of these being 'yes'.

-- Kev



Kevin all solutions may not be the best but sometimes these type of solutions/questions shake our brains. We sometimes do monotonous work, so this solutions help us to break the shackle. We learnt something differently is also interesting.



Post #494116
Posted Friday, May 2, 2008 4:54 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
You can use UNION...

good one...;)




Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com

Post #494120
Posted Friday, May 2, 2008 5:07 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:04 PM
Points: 6,582, Visits: 8,861
Since the question clearly states:

The condition should not use both IN and OR operators.


use could use:
where DatePart(m, ) IN (1,3,4,5,7,8)

OR is not used, so since they BOTH aren't used, this is valid.

you also could use:
where DatePart(m, date) = 1
or DatePart(m, date) = 3 ....
as long as you don't use IN, this also would satisify the requirement not to use both.

The question should have stated
The condition should not use either the IN and OR operators.

Yes, I know what was meant. But the requirements didn't adequately specify the intention.


Wayne
Microsoft Certified Master: SQL Server 2008
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #494123
Posted Friday, May 2, 2008 5:46 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, July 25, 2014 6:26 AM
Points: 846, Visits: 850
WayneS (5/2/2008)
Since the question clearly states:

The condition should not use both IN and OR operators.

use could use:
where DatePart(m, ) IN (1,3,4,5,7,8)

OR is not used, so since they BOTH aren't used, this is valid.

Exactly the answer I was about to give. :) I figured the question had to have been misworded, it's a complete no-brainer as is.

Ron Moses


-----
a haiku...

NULL is not zero
NULL is not an empty string
NULL is the unknown
Post #494139
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse