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 01, 2008 8:42 PM
 SSC Journeyman Group: General Forum Members Last Login: Monday, May 04, 2009 4:44 AM Points: 75, Visits: 8
Post #494010
 Posted Thursday, May 01, 2008 8:46 PM
 Ten Centuries Group: General Forum Members Last Login: Monday, December 02, 2013 6:38 AM Points: 1,279, Visits: 2,201
 Very tricky! I made a guess. Yes. Anything is possible.
Post #494011
 Posted Friday, May 02, 2008 1:32 AM
 SSCommitted Group: General Forum Members Last Login: Friday, November 22, 2013 7:27 AM Points: 1,865, Visits: 577
 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 02, 2008 1:33 AM
 SSChasing Mays Group: General Forum Members Last Login: Today @ 5:59 AM Points: 612, Visits: 1,700
 Handy to know...I'm sure I'll be using that in my code very soon!
Post #494070
 Posted Friday, May 02, 2008 1:36 AM
 SSC Eights! Group: General Forum Members Last Login: Thursday, November 28, 2013 7:16 AM Points: 812, Visits: 312
 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 02, 2008 2:12 AM
 Ten Centuries Group: General Forum Members Last Login: Thursday, December 05, 2013 10:15 AM Points: 1,081, Visits: 275
 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 02, 2008 4:46 AM
 SSCertifiable Group: General Forum Members Last Login: Thursday, November 07, 2013 7:19 AM Points: 5,023, Visits: 1,363
 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 02, 2008 4:54 AM
 Ten Centuries Group: General Forum Members Last Login: Tuesday, December 03, 2013 2:28 AM Points: 1,239, Visits: 1,541
 You can use UNION...good one...;) ThanksVinay Kumar-----------------------------------------------------------------Keep Learning - Keep Growing !!!www.GrowWithSql.com
Post #494120
 Posted Friday, May 02, 2008 5:07 AM
 SSCertifiable Group: General Forum Members Last Login: Today @ 6:45 PM Points: 6,464, Visits: 8,545
 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 2008If 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 02, 2008 5:46 AM
 Right there with Babe Group: General Forum Members Last Login: Today @ 10:40 AM Points: 746, Visits: 787
 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