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 Tuesday, April 22, 2008 5:48 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, July 19, 2008 3:54 PM
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.
Post #488994
Posted Wednesday, June 4, 2008 1:53 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, December 13, 2013 5:45 AM
Points: 342, Visits: 54
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
Post #511747
Posted Wednesday, June 4, 2008 2:07 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, December 13, 2013 5:45 AM
Points: 342, Visits: 54
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..;)
Post #511757
Posted Thursday, July 10, 2008 3:05 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, June 16, 2010 1:09 AM
Points: 218, Visits: 15
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
Post #531439
« Prev Topic | Next Topic »

Add to briefcase «««12345

Permissions Expand / Collapse