I can't seem to get this to work the way I need it to. I have two tables Assignment
and Event
.
Assignment
StartDate EndDate Equipment
4/1/2016 4/23/2016 1001
4/3/2016 4/10/2016 1002
3/30/2016 4/20/2016 1003
Event
StartDate EndDate Equipment Event
4/2/2016 4/3/2016 1001 maintenance
4/8/2016 4/10/2016 1001 maintenance
4/4/2016 4/5/2016 1002 maintenance
I need to join on the equipment and have an output that divides the Assignment using the events. For this sample data I would have an output that looks something like this:
StartDate EndDate Equipment EventStatus
4/1/2016 4/2/2016 1001 Active
4/2/2016 4/3/2016 1001 maintenance
4/3/2016 4/8/2016 1001 Active
4/8/2016 4/10/2016 1001 maintenance
4/10/2016 4/23/2016 1001 Active
4/3/2016 4/4/2016 1002 Active
4/4/2016 4/5/2016 1002 maintenance
4/5/2016 4/10/2016 1002 Active
3/30/2016 4/20/2016 1003 Active
So for Equipment number 1001; it was put into an assignment then had maintenance twice. That maintenance split the assignment into 5 parts like so:
---------------------------------------------------------------------
| Active |maintenance| Active |maintenance| Active |
---------------------------------------------------------------------
Each of those parts must have its own row with the start and end date for that section. How can I write a query to make this work?
Best Answer
Another possible solution: (thanks John Eisbrener for the sample data)