|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Monday, May 04, 2009 4:44 AM
Points: 75,
Visits: 8
|
|
| Comments posted to this topic are about the item T-SQL query
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 7:19 AM
Points: 1,279,
Visits: 2,191
|
|
| Very tricky! I made a guess. Yes. Anything is possible.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 8:55 AM
Points: 1,865,
Visits: 556
|
|
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
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
| Handy to know...I'm sure I'll be using that in my code very soon!
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Thursday, April 18, 2013 5:10 AM
Points: 766,
Visits: 274
|
|
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.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 2:34 AM
Points: 931,
Visits: 222
|
|
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!
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Thursday, May 16, 2013 2:50 AM
Points: 4,785,
Visits: 1,334
|
|
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.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 12:50 AM
Points: 1,076,
Visits: 1,134
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 10:50 AM
Points: 6,367,
Visits: 8,227
|
|
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
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 10:09 AM
Points: 648,
Visits: 684
|
|
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
|
|
|
|