See if a datetime is between another records datetime
Posted on 2012-12-28
Hopefully I can explain myself on this one.
I work for a trucking company and we trying to see if we have overlapping times.
I have a query that tells me the StartTime and EndTime for trips based on a specific vehiicle that performs the services. These are two columns and look something like so:
Order StartTime EndTime
123 2012-12-28 11:29:26.000 2012-12-28 13:41:02.000
344 2012-12-28 08:35:15.000 2012-12-28 11:10:53.000
xyx 2012-12-28 11:45:26.000 2012-12-28 11:59:26.000
I would like to add a column that checks for overlapping times. So lets say I have an Order xyx and the start time falls within that of the times already indicated, then have a column that basically flags it using a SELECT Query.
An example would be lets say Order 'xyz' above has the start time of '2012-12-28 11:45:26.000' well that would be flagged, because using the example I have above it can't be because during that time, Order 123 was being performed. Same would go for the End Time.
Just trying to figure out an easy way of identify those that overlap because my trucks can't be at two different places at the same time if that makes sense?