У меня очень простой вопрос, я делаю запрос, который намереваюсь сделать вставку из двух дат во временную таблицу.
То есть 2020-04-01 00:00:00 и 20 -04-01 23:59:00, следовательно, количество дней, которое вам нужно, увеличивается.
Я делаю это таким образом, например:
DECLARE @StartDate DATETIME = '2020-04-01'
DECLARE @EndDate DATETIME = '2020-04-01'
SET @StartDate = @StartDate + '00:00:00'
SET @EndDate = @EndDate + '23:59:00'
WHILE (@StartDate <= @EndDate)
BEGIN
--Insert into a temp table
set @StartDate = DATEADD(DAY, 1, @StartDate);
set @EndDate = DATEADD(day, 1, @EndDate);
print @StartDate
print @EndDate
END;
, однако это входит в повторяющийся цикл и не останавливается. Кроме того, это не только уважение приращения дня, в котором я нуждаюсь.
Может кто-нибудь помочь мне с этим, пожалуйста.
Я хочу добраться до этого:
Initial дата: 2020-04-01 00: 00: 00.
Дата окончания: 2020-04-01 23: 59: 00.
Приращение начального дня 2020-04-02 00:00 : 00
Увеличение даты окончания: 2020-04-02 23: 59: 00.
Мой запрос вызывает у меня:
Apr 2 2020 12:00AM
Apr 2 2020 11:59PM
Apr 3 2020 12:00AM
Apr 3 2020 11:59PM
Apr 4 2020 12:00AM
Apr 4 2020 11:59PM
Apr 5 2020 12:00AM
Apr 5 2020 11:59PM
Apr 6 2020 12:00AM
Apr 6 2020 11:59PM
Apr 7 2020 12:00AM
Apr 7 2020 11:59PM
Apr 8 2020 12:00AM
Apr 8 2020 11:59PM
Apr 9 2020 12:00AM
Apr 9 2020 11:59PM
Apr 10 2020 12:00AM
Apr 10 2020 11:59PM
Apr 11 2020 12:00AM
Apr 11 2020 11:59PM
Apr 12 2020 12:00AM
Apr 12 2020 11:59PM
Apr 13 2020 12:00AM
Apr 13 2020 11:59PM
Apr 14 2020 12:00AM
Apr 14 2020 11:59PM
Apr 15 2020 12:00AM
Apr 15 2020 11:59PM
Apr 16 2020 12:00AM
Apr 16 2020 11:59PM
Apr 17 2020 12:00AM
Apr 17 2020 11:59PM
Apr 18 2020 12:00AM
Apr 18 2020 11:59PM
Apr 19 2020 12:00AM
Apr 19 2020 11:59PM
Apr 20 2020 12:00AM
Apr 20 2020 11:59PM
Apr 21 2020 12:00AM
Apr 21 2020 11:59PM
Apr 22 2020 12:00AM
Apr 22 2020 11:59PM
Apr 23 2020 12:00AM
Apr 23 2020 11:59PM
Apr 24 2020 12:00AM
Apr 24 2020 11:59PM
Apr 25 2020 12:00AM
Apr 25 2020 11:59PM
Apr 26 2020 12:00AM
Apr 26 2020 11:59PM
Apr 27 2020 12:00AM
Apr 27 2020 11:59PM
Apr 28 2020 12:00AM
Apr 28 2020 11:59PM
Apr 29 2020 12:00AM
Apr 29 2020 11:59PM
Apr 30 2020 12:00AM
Apr 30 2020 11:59PM
May 1 2020 12:00AM
May 1 2020 11:59PM
May 2 2020 12:00AM
May 2 2020 11:59PM
May 3 2020 12:00AM
May 3 2020 11:59PM
May 4 2020 12:00AM
May 4 2020 11:59PM
May 5 2020 12:00AM
May 5 2020 11:59PM
May 6 2020 12:00AM
May 6 2020 11:59PM
May 7 2020 12:00AM
May 7 2020 11:59PM
May 8 2020 12:00AM
May 8 2020 11:59PM
May 9 2020 12:00AM
May 9 2020 11:59PM
May 10 2020 12:00AM
May 10 2020 11:59PM
May 11 2020 12:00AM
May 11 2020 11:59PM
May 12 2020 12:00AM
May 12 2020 11:59PM
May 13 2020 12:00AM
May 13 2020 11:59PM
May 14 2020 12:00AM
May 14 2020 11:59PM
May 15 2020 12:00AM
May 15 2020 11:59PM
May 16 2020 12:00AM
May 16 2020 11:59PM
May 17 2020 12:00AM
May 17 2020 11:59PM
May 18 2020 12:00AM
May 18 2020 11:59PM
May 19 2020 12:00AM
May 19 2020 11:59PM
May 20 2020 12:00AM
May 20 2020 11:59PM
May 21 2020 12:00AM
May 21 2020 11:59PM
May 22 2020 12:00AM
May 22 2020 11:59PM
May 23 2020 12:00AM
May 23 2020 11:59PM
May 24 2020 12:00AM
May 24 2020 11:59PM
May 25 2020 12:00AM
May 25 2020 11:59PM
May 26 2020 12:00AM
May 26 2020 11:59PM
May 27 2020 12:00AM
May 27 2020 11:59PM
May 28 2020 12:00AM
May 28 2020 11:59PM
May 29 2020 12:00AM
May 29 2020 11:59PM
May 30 2020 12:00AM
May 30 2020 11:59PM
May 31 2020 12:00AM
May 31 2020 11:59PM
Jun 1 2020 12:00AM
Jun 1 2020 11:59PM
Jun 2 2020 12:00AM
Jun 2 2020 11:59PM
Jun 3 2020 12:00AM
Jun 3 2020 11:59PM
Jun 4 2020 12:00AM
Jun 4 2020 11:59PM
Jun 5 2020 12:00AM
Jun 5 2020 11:59PM
Jun 6 2020 12:00AM
Jun 6 2020 11:59PM
Jun 7 2020 12:00AM
- Любой предложение?
- Где моя ошибка?.
Спасибо.