Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 T-SQL query Rate Topic Display Mode Topic Options
Author
 Message
 Posted Thursday, May 1, 2008 8:42 PM
 SSC Journeyman Group: General Forum Members Last Login: Monday, May 4, 2009 4:44 AM Points: 75, Visits: 8
Post #494010
 Posted Thursday, May 1, 2008 8:46 PM
 Ten Centuries Group: General Forum Members Last Login: Friday, October 10, 2014 8:13 AM Points: 1,278, Visits: 2,204
 Very tricky! I made a guess. Yes. Anything is possible.
Post #494011
 Posted Friday, May 2, 2008 1:32 AM
 SSCommitted Group: General Forum Members Last Login: Wednesday, May 27, 2015 3:44 AM Points: 1,865, Visits: 596
 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
 Say Hey Kid Group: General Forum Members Last Login: Tuesday, September 13, 2016 8:51 AM Points: 695, Visits: 2,090
 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! Group: General Forum Members Last Login: Thursday, December 1, 2016 5:11 AM Points: 952, Visits: 376
 That was a very nice question for a Friday morning.Another solution would be:datepart(m,dob) between 1 and 8and datepart(m,dob) <> 2and datepart(m,dob) <> 6Though the single condition definitely beats this solution.
Post #494071
 Posted Friday, May 2, 2008 2:12 AM
 Ten Centuries Group: General Forum Members Last Login: Tuesday, November 22, 2016 11:46 AM Points: 1,121, Visits: 356
 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 Group: General Forum Members Last Login: Wednesday, April 20, 2016 3:23 AM Points: 6,049, Visits: 1,407
 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'.-- KevKevin 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 Group: General Forum Members Last Login: Thursday, July 23, 2015 2:40 AM Points: 1,242, Visits: 1,549
 You can use UNION...good one...;) ThanksVinay Kumar-----------------------------------------------------------------Keep Learning - Keep Growing !!!www.GrowWithSql.com
Post #494120
 Posted Friday, May 2, 2008 5:07 AM
 SSCertifiable Group: General Forum Members Last Login: Yesterday @ 9:27 AM Points: 5,911, Visits: 10,368
 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. WayneMicrosoft Certified Master: SQL Server 2008Author - SQL Server T-SQL RecipesIf 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
 Ten Centuries Group: General Forum Members Last Login: Wednesday, May 25, 2016 11:36 AM Points: 1,045, Visits: 996
 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 zeroNULL is not an empty stringNULL is the unknown
Post #494139

 Permissions