Hello everyone,
First, some background information. We have in place a table which records status changes on a work order. The orders normally go through each status only once, however they do occasionally reuse status indicators. For example, an order is placed on hold, released from hold, placed back on hold, released again and so on. The sample data provided is an example of an order with data repeating itself. I need some help with writing a query on this table.
| LOC_CODE | WO_NO | UPDATETIME | WO_STATUS_OLD | WO_STATUS_NEW |
|---|
| xxx | 12345 | 05-01-2013 10:24:00 | WR | SP |
| xxx | 12345 | 05-01-2013 10:39:00 | SP | PM |
| xxx | 12345 | 05-01-2013 11:52:00 | PM | ES |
| xxx | 12345 | 05-01-2013 11:58:00 | ES | MO |
| xxx | 12345 | 05-01-2013 12:03:00 | MO | ES |
| xxx | 12345 | 05-01-2013 12:38:00 | ES | AT |
| xxx | 12345 | 05-01-2013 12:48:00 | AT | RS |
| xxx | 12345 | 05-01-2013 13:01:00 | RS | RA |
| xxx | 12345 | 05-01-2013 13:26:00 | RA | RS |
| xxx | 12345 | 05-01-2013 13:36:00 | RS | RA |
| xxx | 12345 | 05-01-2013 15:35:00 | RA | RS |
| xxx | 12345 | 05-01-2013 15:42:00 | RS | RA |
| xxx | 12345 | 05-01-2013 16:04:00 | RA | RS |
| xxx | 12345 | 05-01-2013 16:42:00 | RS | RA |
| xxx | 12345 | 05-01-2013 19:28:00 | RA | FD |
| xxx | 12345 | 05-01-2013 19:28:00 | FD | SO |
The query (which will in turn be used for a view) will display the elapsed time between status updates (subtract updatetime from the record preceeding). Only the first record for each order at a location would have no elapsed time. The result should look like this:
| LOC_CODE | WO_NO | UPDATETIME | WO_STATUS_OLD | WO_STATUS_NEW | MINUTES_ELAPSED |
|---|
| xxx | 12345 | 05-01-2013 10:24:00 | WR | SP | {null} |
| xxx | 12345 | 05-01-2013 10:39:00 | SP | PM | 15 |
| xxx | 12345 | 05-01-2013 11:52:00 | PM | ES | 73 |
| xxx | 12345 | 05-01-2013 11:58:00 | ES | MO | 6 |
| xxx | 12345 | 05-01-2013 12:03:00 | MO | ES | 5 |
| xxx | 12345 | 05-01-2013 12:38:00 | ES | AT | 35 |
| xxx | 12345 | 05-01-2013 12:48:00 | AT | RS | 10 |
| xxx | 12345 | 05-01-2013 13:01:00 | RS | RA | 13 |
| xxx | 12345 | 05-01-2013 13:26:00 | RA | RS | 25 |
| xxx | 12345 | 05-01-2013 13:36:00 | RS | RA | 10 |
| xxx | 12345 | 05-01-2013 15:35:00 | RA | RS | 119 |
| xxx | 12345 | 05-01-2013 15:42:00 | RS | RA | 7 |
| xxx | 12345 | 05-01-2013 16:04:00 | RA | RS | 22 |
| xxx | 12345 | 05-01-2013 16:42:00 | RS | RA | 38 |
| xxx | 12345 | 05-01-2013 19:28:00 | RA | FD | 166 |
| xxx | 12345 | 05-01-2013 19:28:00 | FD | SO | 0 |
I have been trying various queries, but no luck as of yet. I would appreciate your input.
Thank you,
Patrick