Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


T-SQL Query


T-SQL Query

Author
Message
VM-446915
VM-446915
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 15
Well, the question was whether there is another solution. So there might be many, you just have to say, "Yes". As mentioned above, there are plenty, including "union", "negation/and", subquery, I would add CTE, etc. The answer provided is a correct one for this particular case that is rather mensa-oriented. In large scale systems, you would avoid relying on the modulo due to the fact that month list would have to be as generic as possible... As also mentioned above. However, it was fun to answer.
abiel.andrew
abiel.andrew
Old Hand
Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)

Group: General Forum Members
Points: 375 Visits: 56
rbarryyoung (4/16/2008)
FYI, it is ALWAYS possible to construct a mathematical expression that will fit ANY finite set of numbers. for instance:

WHERE (month(dob)-2) * (month(dob)-6) * (month(dob)-7) * (month(dob)-8) * (month(dob)-11) * (month(dob)-12) = 0



Works just as well.


Fantastic solution....
very good one RBarryYoung w00t
abiel.andrew
abiel.andrew
Old Hand
Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)

Group: General Forum Members
Points: 375 Visits: 56
Norma Jean Claeys (4/21/2008)
select * from stud_mast
join (select 2 choice union select 6 union select 7
union select 8 union select 11 union select 12) choices
where month(dob) = choice


I guess there should be ON condition instead of WHERE clause..Wink
Mayuresh
Mayuresh
SSC Veteran
SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)

Group: General Forum Members
Points: 218 Visits: 17
we can even use
charindex(',' + Convert(varchar(2),month(dob)) + ',', ',2,6,7,8,11,12,') >0

This won't have impact even if the language is not english


MayurArt
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search