0

如果我有 2 天2013-06-032013-06-10例如,我如何打印这两个日期之间所有日期的列表?

例如,这种情况下的列表将是:

2013-06-22
2013-06-23
2013-06-24
2013-06-25
2013-06-26
2013-06-27
2013-06-28
2013-06-29
2013-06-30
2013-07-01
2013-07-02
2013-07-03
2013-07-04
2013-07-05
2013-07-06
2013-07-07
4

2 回答 2

5
DECLARE @Start date = '2013-06-03'
DECLARE @End date = '2013-06-10'

;WITH Dates AS 
(
    SELECT @Start AS [Date]
    UNION ALL
    SELECT DATEADD(DAY, 1, [Date])
    FROM Dates
    WHERE [Date] < @End
)

SELECT [Date] 
FROM Dates
OPTION (MAXRECURSION 0)
于 2013-06-18T12:47:30.403 回答
-3

我想你正在寻找这个:

SELECT * FROM TABLE_NAME WHERE DATE_COLUMN_NAME BETWEEN '03-JUNE-2013' 和 '10-JUNE-2013'

于 2013-06-18T12:48:18.673 回答