For a current project I am working I need to return an aggregate report based on date ranges.
I have 3 types of reports, yearly, monthly and daily.
To assis
A static number table is useful, single column, say 8000 rows FROM 0 TO 7999
(Not checked)
DECLARE @Start smalldatetime, @End smalldatetime, @Diff int
SELECT @Start = '2006-01-01 11:10:00', @End = '2009-05-05 08:00:00', @diff = DATEDIFF(year,@start,@end)
SELECT
DATEADD(year,N.Number,@Start)
FROM
dbo.Number N
WHERE
N.Number <= @diff