递归方式生成指定月份所有日期
DECLARE @SELECTMONTH NVARCHAR(7)=N'2017-02';
;
WITH MONTHDAYTABLE([DATE]) AS(
SELECT CONVERT(DATETIME,@SELECTMONTH+'-01')
UNION ALL
SELECT DATEADD(D,1,MONTHDAYTABLE.[DATE]) AS DATE
FROM MONTHDAYTABLE
WHERE DATEADD(D,1,MONTHDAYTABLE.[DATE])<DATEADD(MONTH,1,@SELECTMONTH+'-01')
)
SELECT * FROM MonthDayTable