利用遍历自动生成日期表

背景:要自动生成一个日期表

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 a
OPTION(MAXRECURSION 366)

 

上一篇:C#DataTable(转List /JSON/字典 互转)


下一篇:newlife.xcode跨库跨表数据查询