maybe its too simple or maybe its too complicated, but I cant find any solution around this problem. Or maybe i just spent too much time looking at the screen trying to solve it, but now i am officially out of all clues.
Say I have a SQL Table like this...
id AideCode StartTime EndTime
602 1017 2014-01-13 07:00:00 2014-01-13 19:00:00
2442 1017 2014-01-14 07:00:00 2014-01-14 19:00:00
4684 1017 2014-01-15 08:00:00 2014-01-16 08:00:00
6569 1017 2014-01-16 08:00:00 2014-01-17 08:00:00
8404 1017 2014-01-17 08:00:00 2014-01-18 08:00:00
9968 1017 2014-01-18 08:00:00 2014-01-19 08:00:00
602 1018 2014-01-13 03:00:00 2014-01-13 13:00:00
602 1018 2014-01-14 10:00:00 2014-01-13 18:00:00
Now I want to find out if anyone is available on 2014-01-13 between 4am - 5 am, basiclly between '2014-01-13 04:00:00' and '2014-01-13 05:00:00', it should return 1017 because it is available between that time slot.
Also I want to find out if anyone is available on 2014-01-14 between 7am - 9 am, basiclly between '2014-01-14 07:00:00' and '2014-01-14 09:00:00', it should return 1018 because it is available between that time slot.
So what will be that magical sql query look