背景:自动生成日期表
DECLARE @year INT=year(getdate()); ---DECLARE @year INT=year(:endTime); WITH t AS (SELECT CAST( CAST(@year AS VARCHAR(4)) + '-1-1' AS DATE) AS Dt UNION ALL SELECT DATEADD(DAY,1, t.Dt) FROM t WHERE t.Dt<CAST(@year AS VARCHAR(4)) + '-12-31') select * from t option (maxrecursion 400)