我找到了这个解决方案,但它限制在2047天.
DECLARE @MinDate DATE, @MaxDate DATE;
SELECT DATEADD(DAY,number,@MinDate) [Date]
FROM master.dbo.spt_values
WHERE type = 'P'
AND number > 0
AND DATEADD(DAY,number,@MinDate) <= @MaxDate
我怎样才能延长最大天数?
最佳答案 请尝试使用CTE:
DECLARE @MinDate DATE, @MaxDate DATE;
SELECT @MinDate =DATEADD(year,-11 ,GETDATE()), @MaxDate =getdate();
;WITH Dates AS
(
SELECT n = @MinDate
UNION ALL
SELECT DATEADD(day, 1, n)
FROM Dates
WHERE DATEADD(day, 1, n) <= @MaxDate
)
SELECT n
FROM Dates
OPTION (MAXRECURSION 0);