Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select Date of Birth that is too old or too young

Author  Topic 

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2011-05-10 : 14:37:12
I have a table with a list of birth dates. I need to be able to select the birth dates that are either too old to be students or too young to be students. I was trying a MIN/MAX date but that only brings up one "oldest" or one "newest" birth date.

Here is what I was trying:

Select
SSN, LastName, FirstName, SyStudentID, DOB
FROM
syStudent
WHERE
DOB = (SELECT MAX(DOB) From Systudent)
Group BY
SSN, LastName, FirstName, SyStudentId, DOB

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-10 : 14:44:18
Assuming pre-college school ages (Kindergarten through 12):

SELECT SSN, LastName, FirstName, SyStudentID, DOB
FROM syStudent
WHERE DOB < DATEADD(year, -19, GETDATE()) OR DOB > DATEADD(year, -6, GETDATE())

You can adjust the year range accordingly.
Go to Top of Page

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2011-05-10 : 15:04:40
Thank you so much! That worked very well.
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-05-10 : 16:52:23
>>too old to be a student
?
I was thinking of finally getting a degree after I retire.
I probably won't hold out for an athletic scholarship though...


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -