Example : If the route runs between 12:15 AM - 07:30 AM... And some drivers availability is as follow.. Case 1) 01:00 AM - 5:30 AM Or Case 2) 11:00 PM - 02:00 AM Or Case 3) 04:00 AM - 9:00 AM Or Case 4) 11:30 PM - 08:00 AM You are given me the answer for case 1...However... My query should be able to pick these case2,3,and 4 because all these cases either fall between the routes run time or cover the route totally like in case 4.... For case 2 if difference between case2's end time and route's start time is greater than > 30 mins, it should be considered. For case 3 if difference between case3's start time and route's end time is greater than > 30 mins, it should be considered. I need to modify my query as above example...how will I do that ? SELECT * FROM myTbl WHERE PERSON_ID=[pid] AND ( start_datetime between [datetime1] and [datetime2] OR end_datetime between [datetimte1] and [datetime2] ) Code (markup):
Your arguments are missing a piece of logic as the route needs to include the number of hours required to complete the job. With this type of logic you would normally have: Cannot start before X time Will take Y hours Must finish before Z time
That is why I have route start and end time ....The idea is also Full time drivers shouldnt get more than 40 hrs per wk and part times shouldnt get more than 20...if they do , you switch the extra hours between other drivers who has same route knowledge for the same day...