Thursday, 19 February 2015

SQL Server - Get dates between two dates

DECLARE @MinDate DATE = '2014-01-01',
        @MaxDate DATE = '2014-02-06';

SELECT  TOP (DATEDIFF(DAY, @MinDate, @MaxDate) + 1)
        Date = DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY a.object_id) - 1, @MinDate)
FROM    sys.all_objects a
        CROSS JOIN sys.all_objects b;

        

Kindly Bookmark and Share it:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...