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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 PeopleSoft SQL - Listing students of certain ages

Author  Topic 

beamer7296
Starting Member

2 Posts

Posted - 2007-11-09 : 11:11:43
I am using PeopleSoft's query manager.

Basically, I have 2 fields, A.BIRTHDATE and F.START_DT.

I want to add an expression that will allow me to only list "students" who will be 21 when the class begins (start date).

I have an extensive programming background, but I've never written any SQL. I would really appreciate any help that you can offer!

beamer7296
Starting Member

2 Posts

Posted - 2007-11-09 : 11:14:52
The birthdate and stardate fields are currently in the following format: MM/DD/YYYY
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-09 : 11:18:06
[code]WHERE datediff(year, A.BIRTHDATE, F.START_DT) >= 21[/code]

also take a look at http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64762 section Finding Age


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-11-09 : 11:38:45
quote:
Originally posted by khtan

WHERE datediff(year, A.BIRTHDATE, F.START_DT) >= 21


also take a look at http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64762 section Finding Age


KH
[spoiler]Time is always against us[/spoiler]





I'm not sure that really works; this gives you an age of 1 year:
select datediff(year,'20061231','20070101')


This function returns age in years.
Age Function F_AGE_IN_YEARS:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462




CODO ERGO SUM
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-09 : 11:41:53
Well, it depends on the accuracy required. 1 will still be less than 21 and the where condition will be false anyway


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-11-09 : 11:48:48
This should work, provided that the column datatypes are datetime:

where
F.START_DT >=
-- 21st Birthday
dateadd(year,21,A.BIRTHDATE)


CODO ERGO SUM
Go to Top of Page
   

- Advertisement -