获取一系列日期之间的日期
我需要使用 SQL Server 2005 获取日期范围内的所有日期
I need to get all the dates present in the date range using SQL Server 2005
推荐答案
给你:
DECLARE @DateFrom smalldatetime, @DateTo smalldatetime;
SET @DateFrom='20000101';
SET @DateTo='20081231';
-------------------------------
WITH T(date)
AS
(
SELECT @DateFrom
UNION ALL
SELECT DateAdd(day,1,T.date) FROM T WHERE T.date < @DateTo
)
SELECT date FROM T OPTION (MAXRECURSION 32767);
相关文章