要實現的效果:查詢從Date From 到 To 之間的 所有日期; 示例代碼如下: DECLARE @DATE_FROM DATETIME = N'2016-05-16';--N'2015-05-16';DECLARE @DATE_TO DATETIME = N'2016-05-17';WITH ...
要實現的效果:查詢從Date From 到 To 之間的 所有日期;
示例代碼如下:
DECLARE @DATE_FROM DATETIME = N'2016-05-16';--N'2015-05-16';
DECLARE @DATE_TO DATETIME = N'2016-05-17';
WITH tmpDays AS
(
SELECT @DATE_FROM DATE_VALUE
UNION ALL
SELECT DATE_VALUE + 1
FROM tmpDays
WHERE DATE_VALUE + 1 <= @DATE_TO
)
SELECT * FROM tmpDays OPTION (MAXRECURSION 0);