Revision history  [back]

The following query gets all dates between two dates as a table:

with dates as (
SELECT  TOP (DATEDIFF(DAY, '20160101', '20161231') + 1)
        cast(DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY a.object_id) - 1, '20160101') as date) dayDate
FROM    sys.all_objects a
        CROSS JOIN sys.all_objects b
)

select * from dates

The following query gets all dates between two dates as a table:

with dates as (
SELECT  TOP (DATEDIFF(DAY, '20160101', '20161231') + 1)
        cast(DATEADD(DAY, ROW_NUMBER() ROWNUMBER() OVER(ORDER BY a.object_id) a.objectid) - 1, '20160101') as date) dayDate
FROM    sys.all_objects sys.allobjects a
        CROSS JOIN sys.all_objects sys.allobjects b
)
)

select * from dates