in reply to Trying to select all records that match a datetime range.
If I understand you correctly, you have several cases you need to cover, like so:
and you want to return records for cases 3, 4, 5, and 6, but you're not getting case 6. I normally cover these cases by:Desired range: +---------------+ Case 1,2: +-1-+ +---2--+ Case 3,4: +----3-----+ +--------4-----------+ Case 5: +---5----+ Case 6: +------------------6----------------+
That should catch all the cases for you. The SQL code I normally use resembles:
...roboticusselect * from table where (start_time between desired_start and desired_stop) or (end_time between desired_start and desired_end) or (desired_start between start_time and end_time) or (desired_stop between start_time and end_time)
|
|---|