Hello,
I have two sets of records in a table namely ACTIVITY and DELAY for a particular machine in a particular shiftdate and shift. During some shiftdates and shifts OVERLAP occurs between Acitivty and Delay .The DELAY records occurring between ACTIVITY records should be given the priority and ACTIVITY records should split accordingly around DELAY records thus removing the OVERLAP between Activity and Delays
Please note that not always the Overlap occurs
Input
Type | Shiftdate | Shift# | MachineID | StartTime | EndTime |
Activity | 1/1/2013 | 1 | 780 | 1/1/13 7:00 AM | 1/1/13 8:00 AM |
Activity | 1/1/2013 | 1 | 780 | 1/1/13 8:00 AM | 1/1/13 8:40 AM |
Activity | 1/2/2013 | 1 | 780 | 1/2/13 7:00 AM | 1/2/13 8:00 AM |
Activity | 1/2/2013 | 1 | 780 | 1/2/13 8:00 AM | 1/2/13 8:40 AM |
Activity | 1/1/2013 | 1 | 781 | 1/1/13 7:00 AM | 1/1/13 8:00 AM |
Activity | 1/1/2013 | 1 | 781 | 1/1/13 8:00 AM | 1/1/13 8:40 AM |
Activity | 1/2/2013 | 1 | 781 | 1/2/13 7:00 AM | 1/2/13 8:00 AM |
Activity | 1/2/2013 | 1 | 781 | 1/2/13 8:00 AM | 1/2/13 8:40 AM |
Delay | 1/1/2013 | 1 | 780 | 1/1/13 7:10 AM | 1/1/13 7:20 AM |
Delay | 1/1/2013 | 1 | 780 | 1/1/13 7:30 AM | 1/1/13 7:45 AM |
Delay | 1/1/2013 | 1 | 780 | 1/1/13 7:51 AM | 1/1/13 8:03 AM |
Delay | 1/1/2013 | 1 | 780 | 1/1/13 8:15 AM | 1/1/13 8:30 AM |
Delay | 1/2/2013 | 1 | 780 | 1/2/13 6:54 AM | 1/2/13 7:10 AM |
Delay | 1/2/2013 | 1 | 780 | 1/2/13 7:30 AM | 1/2/13 7:45 AM |
Delay | 1/2/2013 | 1 | 780 | 1/2/13 8:15 AM | 1/2/13 8:30 AM |
Delay | 1/2/2013 | 1 | 780 | 1/2/13 8:35 AM | 1/2/13 8:43 AM |
Delay | 1/1/2013 | 1 | 781 | 1/1/13 7:10 AM | 1/1/13 7:20 AM |
Delay | 1/1/2013 | 1 | 781 | 1/1/13 7:30 AM | 1/1/13 7:45 AM |
Delay | 1/1/2013 | 1 | 781 | 1/1/13 7:51 AM | 1/1/13 8:03 AM |
Delay | 1/1/2013 | 1 | 781 | 1/1/13 8:15 AM | 1/1/13 8:30 AM |
Delay | 1/2/2013 | 1 | 781 | 1/2/13 6:54 AM | 1/2/13 7:10 AM |
Delay | 1/2/2013 | 1 | 781 | 1/2/13 7:30 AM | 1/2/13 7:45 AM |
Delay | 1/2/2013 | 1 | 781 | 1/2/13 8:15 AM | 1/2/13 8:30 AM |
Delay | 1/2/2013 | 1 | 781 | 1/2/13 8:35 AM | 1/2/13 8:43 AM |
Activity 1/3/2013 1 780 1/3/13 9:00 AM 1/3/13
10:00 AM
DELAY 1/3/2013 1 780 1/3/13 10:00 AM 1/3/13 11:00
AM
OUTPUT
Type | Shiftdate | Shift# | MachineID | StartTime | EndTime |
Activity | 1/1/2013 | 1 | 780 | 1/1/13 7:00 AM | 1/1/13 7:10 AM |
Delay | 1/1/2013 | 1 | 780 | 1/1/13 7:10 AM | 1/1/13 7:20 AM |
Activity | 1/1/2013 | 1 | 780 | 1/1/13 7:20 AM | 1/1/13 7:30 AM |
Delay | 1/1/2013 | 1 | 780 | 1/1/13 7:30 AM | 1/1/13 7:45 AM |
Activity | 1/1/2013 | 1 | 780 | 1/1/13 7:45 AM | 1/1/13 7:51 AM |
Delay | 1/1/2013 | 1 | 780 | 1/1/13 7:51 AM | 1/1/13 8:03 AM |
Activity | 1/1/2013 | 1 | 780 | 1/1/13 8:03 AM | 1/1/13 8:15 AM |
Delay | 1/1/2013 | 1 | 780 | 1/1/13 8:15 AM | 1/1/13 8:30 AM |
Activity | 1/1/2013 | 1 | 780 | 1/1/13 8:30 AM | 1/1/13 8:40 AM |
Delay | 1/2/2013 | 1 | 780 | 1/2/13 6:54 AM | 1/2/13 7:10 AM |
Activity | 1/2/2013 | 1 | 780 | 1/2/13 7:10 AM | 1/2/13 7:30 AM |
Delay | 1/2/2013 | 1 | 780 | 1/2/13 7:30 AM | 1/2/13 7:45 AM |
Activity | 1/2/2013 | 1 | 780 | 1/2/13 7:45 AM | 1/2/13 8:00 AM |
Activity | 1/2/2013 | 1 | 780 | 1/2/13 8:00 AM | 1/2/13 8:15 AM |
Delay | 1/2/2013 | 1 | 780 | 1/2/13 8:15 AM | 1/2/13 8:30 AM |
Activity | 1/2/2013 | 1 | 780 | 1/2/13 8:30 AM | 1/2/13 8:35 AM |
Delay | 1/2/2013 | 1 | 780 | 1/2/13 8:35 AM | 1/2/13 8:43 AM |
Activity | 1/1/2013 | 1 | 781 | 1/1/13 7:00 AM | 1/1/13 7:10 AM |
Delay | 1/1/2013 | 1 | 781 | 1/1/13 7:10 AM | 1/1/13 7:20 AM |
Activity | 1/1/2013 | 1 | 781 | 1/1/13 7:20 AM | 1/1/13 7:30 AM |
Delay | 1/1/2013 | 1 | 781 | 1/1/13 7:30 AM | 1/1/13 7:45 AM |
Activity | 1/1/2013 | 1 | 781 | 1/1/13 7:45 AM | 1/1/13 7:51 AM |
Delay | 1/1/2013 | 1 | 781 | 1/1/13 7:51 AM | 1/1/13 8:03 AM |
Activity | 1/1/2013 | 1 | 781 | 1/1/13 8:03 AM | 1/1/13 8:15 AM |
Delay | 1/1/2013 | 1 | 781 | 1/1/13 8:15 AM | 1/1/13 8:30 AM |
Activity | 1/1/2013 | 1 | 781 | 1/1/13 8:30 AM | 1/1/13 8:40 AM |
Delay | 1/2/2013 | 1 | 781 | 1/2/13 6:54 AM | 1/2/13 7:10 AM |
Activity | 1/2/2013 | 1 | 781 | 1/2/13 7:10 AM | 1/2/13 7:30 AM |
Delay | 1/2/2013 | 1 | 781 | 1/2/13 7:30 AM | 1/2/13 7:45 AM |
Activity | 1/2/2013 | 1 | 781 | 1/2/13 7:45 AM | 1/2/13 8:00 AM |
Activity | 1/2/2013 | 1 | 781 | 1/2/13 8:00 AM | 1/2/13 8:15 AM |
Delay | 1/2/2013 | 1 | 781 | 1/2/13 8:15 AM | 1/2/13 8:30 AM |
Activity | 1/2/2013 | 1 | 781 | 1/2/13 8:30 AM | 1/2/13 8:35 AM |
Delay | 1/2/2013 | 1 | 781 | 1/2/13 8:35 AM | 1/2/13 8:43 AM |
Activity 1/3/2013 1 780 1/3/13 9:00 AM 1/3/13
10:00 AM
DELAY 1/3/2013 1 780 1/3/13 10:00 AM 1/3/13 11:00
AM
Would appreciate the help