我能夠通過此獲得兩個日期之間的所有日期。使用基於集合的方法在SQL Server中的多個兩個日期之間打印所有日期的日期
DECLARE @MinDate DATE = '20140101' ,
@MaxDate DATE = '20140106';
SELECT TOP (DATEDIFF(DAY, @MinDate, @MaxDate) + 1)
DATEADD(DAY, ROW_NUMBER() OVER (ORDER BY a.object_id) - 1, @MinDate)
FROM
sys.all_objects a
CROSS JOIN
sys.all_objects b
現在,我得到一個結果集是這樣的:
-----------------------------------------------------------
| ID | StartDate | EndDate |
-----------------------------------------------------------
| 1 | 2017-05-12 00:00:00.000 | 2017-05-15 00:00:00.000 |
| 2 | 2018-08-10 00:00:00.000 | 2018-08-13 00:00:00.000 |
| 3 | 2019-02-12 00:00:00.000 | 2019-02-13 00:00:00.000 |
-----------------------------------------------------------
我需要找到所有天都開始日期和結束日期在此表中,與預期的結果應該像下面:
---------------------------
| AllDates |
---------------------------
| 2017-05-12 00:00:00.000 |
| 2017-05-13 00:00:00.000 |
| 2017-05-14 00:00:00.000 |
| 2017-05-15 00:00:00.000 |
| 2018-08-10 00:00:00.000 |
| 2018-08-11 00:00:00.000 |
| 2018-08-12 00:00:00.000 |
| 2018-08-13 00:00:00.000 |
| 2019-02-12 00:00:00.000 |
| 2019-02-13 00:00:00.000 |
---------------------------
沒有在SQL Server中使用用戶定義的函數,這隻能通過使用基於集合的方法來實現嗎?