Проверьте совпадение дат
i have this date range: 2020-03-12 to 2020-03-13 and then i have the sql table with the following data: RoomNumber ReservationStartDate ReservationEndDate 101 2020-02-17 2020-02-22 101 2020-02-14 2020-03-22 101 2020-03-11 2020-03-14 101 2020-04-11 2020-04-14 i want to insert this date range 2020-03-12 to 2020-03-13 into the table only if the dates do not overlap with any of the date ranges in the table. Any one who can help with the sql code to achieve that result?
Что я уже пробовал:
Я попробовал Решение ниже, но оно не работает
<pre>select COUNT(*) from ResTest where roomNumber = 101 and ReservationTo > '2020-03-12' and ReservationFrom < '2020-03-13' insert into ResTest (RoomNumber, ReservationFrom , ReservationTo) select RoomNumber, resStartDate, resEndDate from (values (101, '2020-03-12', '2020-03-13') ) v(RoomNumber, resStartDate, resEndDate) where not exists (select 1 from ResTest where ResTest.RoomNumber = v.RoomNumber and ResTest.ReservationFrom > v.resStartDate and ResTest.ReservationTo < v.resEndDate )