我试图在当前月份和最后两个月之间存在所有日期.
例如:今天10-01-2019使用sql脚本,我将获得2018-10-01和2019-01-31之间的所有日期.
with cte as
(
select getdate() as n
union all
select dateadd(DAY,-1,n) from cte where month(dateadd(dd,-1,n)) < month(DATEADD(month, -3, getdate())) --and month(DATEADD(month, 0, getdate()))
union all
select dateadd(DAY,-1,n) from cte where month(dateadd(dd,-1,n)) > month(DATEADD(month, 0, getdate()))
)
select * from cte
Run Code Online (Sandbox Code Playgroud)
我明白了
错误消息530,级别16,状态1,行1语句终止.在语句完成之前,最大递归100已用尽.