Technical Article

Generate Dates Between Supplied Range - MSQL 2005

,

Display Dates as rows between Specified Date Range.

DECLARE @STARTDATE DATETIME
DECLARE @ENDDATE DATETIME

SET @STARTDATE = '2006-01-27'
SET @ENDDATE = '2006-02-20'

SELECT @STARTDATE + RowNum -1 AS DATEVAL FROM
      (
            SELECT row_number() OVER (ORDER BY 1) AS RowNum FROM sys.all_objects
      ) RowTable 
WHERE RowNum <= DATEDIFF(d,@STARTDATE,@ENDDATE) + 1

Rate

5 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (2)

You rated this post out of 5. Change rating