Suppose you have a table with date ranges for which those dates are NOT available.
+------------+------------+
| StartDate | EndDate |
+------------+------------+
| 2014-10-1 | 2014-10-15 |
+------------+------------+
| 2014-11-4 | 2014-11-28 |
+------------+------------+
| 2014-12-17 | NULL |
+------------+------------+
An EndDate of NULL means till the end of time. So there are no available dates after 12/17.
Given a date range, I need to find the first available date. I'm not that great at SQL and I can't think of how this could be done.
Examples: Given the desired date range
2014-10-13 to 2014-11-17, the query should return 2014-10-16
2014-10-13 to 2014-11-30, the query should return 2014-10-16
2014-10-21 to 2014-11-30, the query should return 2014-10-21
2014-12-01 to 2015-1-13, the query should return 2014-12-01
I'd appreciate any help. Thanks.