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.
Author |
Topic |
jql
Starting Member
30 Posts |
Posted - 2011-11-28 : 05:57:44
|
Hi, i need to select a list of people who were between the age of 30 & 35 between 01-apr-2010 and 31-mar-2011. i have struggled for a day now in trying to work this out. can anyone please help?Thanks |
|
sql-programmers
Posting Yak Master
190 Posts |
Posted - 2011-11-28 : 06:30:51
|
Try this script,CREATE TABLE #temp([Name] VARCHAR(100),DOB DATETIME)INSERT INTO #temp ( Name, DOB )VALUES ( 'XXX','1/1/1980' )INSERT INTO #temp ( Name, DOB )VALUES ( 'YYY','6/25/1979' )INSERT INTO #temp ( Name, DOB )VALUES ( 'ZZZ','6/25/1981' )SELECT DATEDIFF(yyyy,DOB,'4/1/2010'),DATEDIFF(yyyy,DOB,'3/31/2011'),* FROM #temp WHERE DATEDIFF(yyyy,DOB,'4/1/2010')>=30 AND DATEDIFF(yyyy,DOB,'3/31/2011')<=35DROP TABLE #tempSQL Server Programmers and Consultantshttp://www.sql-programmers.com/ |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-11-28 : 06:56:12
|
quote: Originally posted by sql-programmers Try this script,CREATE TABLE #temp([Name] VARCHAR(100),DOB DATETIME)INSERT INTO #temp ( Name, DOB )VALUES ( 'XXX','1/1/1980' )INSERT INTO #temp ( Name, DOB )VALUES ( 'YYY','6/25/1979' )INSERT INTO #temp ( Name, DOB )VALUES ( 'ZZZ','6/25/1981' )SELECT DATEDIFF(yyyy,DOB,'4/1/2010'),DATEDIFF(yyyy,DOB,'3/31/2011'),* FROM #temp WHERE DATEDIFF(yyyy,DOB,'4/1/2010')>=30 AND DATEDIFF(yyyy,DOB,'3/31/2011')<=35DROP TABLE #tempSQL Server Programmers and Consultantshttp://www.sql-programmers.com/
This is not accurate. Search for calculating Age in this forumMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|