Wednesday, 29 April 2015

How to display all days in a month by SQL Server?

How to display all days in a month by SQL Server?

DECLARE @RepMonth as datetime
SET @RepMonth = '04/01/2015';
WITH DayList (DayDate) AS
(
    SELECT @RepMonth
    UNION ALL
    SELECT DATEADD(d, 1, DayDate)
    FROM DayList
    WHERE (DayDate < DATEADD(d, -1, DATEADD(m, 1, @RepMonth)))
)
SELECT *
FROM DayList

No comments:

Post a Comment