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 2005 Forums
 Transact-SQL (2005)
 Age function help - date ranges

Author  Topic 

shawnmolloy
Yak Posting Veteran

93 Posts

Posted - 2008-05-22 : 21:34:46
Hey,

I woudl like to take an age range (Say 22-27) and determine the min and max year, and then take those two DateTime Year values and do a SELECT from a column titled "Birthday Year", which is a an int value like '1984'. Could someone give me a hand with this?


/* Value 1: 1978
Value 2: 1988
*/

SELECT(???) FROM User WHERE ['BirthdayYear'] <> (?Age Function?)
GO


Thanks.

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-05-22 : 22:51:14
Do you have sample data and expected results?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-23 : 03:02:03
SELECT * FROM User WHERE BirtDayYear BTWEEN DATEPART(YEAR, GETDATE()) - 27 AND DATEPART(YEAR, GETDATE()) - 22


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

shawnmolloy
Yak Posting Veteran

93 Posts

Posted - 2008-05-23 : 21:49:57
Worked like a dream! I was fooling around with DateDif but this seems like a much simpler way. Thanks again Peso.
Go to Top of Page
   

- Advertisement -