Computing the age of someone is more difficult than it might seem when you take into account different month lengths, leap year, and other things. Function F_AGE_IN_YEARS from the following link returns age in years:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462Here is a sample query using the F_AGE_IN_YEARS function that gives output like you showed:select [0-4] = sum(case when Age between 0 and 4 then 1 else 0 end) , [5-9] = sum(case when Age between 5 and 9 then 1 else 0 end) , [10-14] = sum(case when Age between 10 and 14 then 1 else 0 end) , [15-17] = sum(case when Age between 15 and 17 then 1 else 0 end)from ( select [Age] = dbo.F_AGE_IN_YEARS( aa.START_DATE, getdate()) from ( -- test data select START_DATE =convert(datetime,'20040407') union all select '20000407' union all select '19951011' union all select '19920101' union all select '19910101' ) aa ) a
Results:0-4 5-9 10-14 15-17 ----------- ----------- ----------- ----------- 1 1 1 2(1 row(s) affected)
CODO ERGO SUM