I have a table (Sequence) which determines the order of operations and based on this table we have to pull the corresponding operations from a summary table (Summary) and display the rest of the attributes.
Sequence
PART OP1 OP2 OP3 OP4 OP5 OP6 OP7 OP8
ABC 2 3 4 5 1 0 0 0
Summary
Part Serail OP Status Date Accomplished
ABC 2196 1 OPEN 18-Jul-14
ABC 2196 2 PREV ACCO 21-Jan-11
ABC 2196 3 PREV ACCO 21-Jan-11
ABC 2196 4 PREV ACCO 21-Jan-11
ABC 2196 5 COMPLETE 19-Jan-11
ABC 5596 1 COMPLETE 30-Jun-16
ABC 5596 5 COMPLETE 30-Jun-16
ABC 5845 1 COMPLETE 25-Nov-17
ABC 5845 2 PREV ACCO 27-Aug-09
ABC 5845 5 PREV ACCO 27-Aug-09
ABC 6076 1 OPEN 18-Jul-14
ABC 6076 2 PREV ACCO 2-Apr-12
ABC 6076 5 COMPLETE 29-Mar-12
ABC 6076 10 DELETED 10-MAR-19
get the value for OP1, and see for what all serail its associated with and display the corresponding Status and Date Accomplished. If its doesnt exist a particular serial then display N/A
Example -Serial 5596
has only operations 1 and 5 in the summary, but in the sequence table the part has operations 1,2,3,4,5. So the first 3 operations will be N/AIf there are operations that only exist in the summary but not in the sequence tables then display them at the bottom for the serial that its tied with. Ex -
Serial 6076
has operation 10 with status Deleted that only exist in Summary but not in the sequence table, in that case we display that at the end as operation 6 after we process everything from the sequence table.
My Result should be as below
Part Serial OP Status Date
ABC 2196 1 PREV ACCO 21-Jan-11
ABC 2196 2 PREV ACCO 21-Jan-11
ABC 2196 3 PREV ACCO 21-Jan-11
ABC 2196 4 COMPLETE 19-Jan-11
ABC 2196 5 OPEN 18-Jul-14
ABC 5596 1 N/A N/A
ABC 5596 2 N/A N/A
ABC 5596 3 N/A N/A
ABC 5596 4 COMPLETE 30-Jun-16
ABC 5596 5 COMPLETE 30-Jun-16
ABC 5845 1 PREV ACCO 27-Aug-09
ABC 5845 2 N/A N/A
ABC 5845 3 N/A N/A
ABC 5845 4 PREV ACCO 27-Aug-09
ABC 5845 5 COMPLETE 25-Nov-17
ABC 6076 1 PREV ACC 2-Apr-12
ABC 6076 2 N/A N/A
ABC 6076 3 N/A N/A
ABC 6076 4 COMPLETE 29-Mar-12
ABC 6076 5 OPEN 18-Jul-14
ABC 6076 6 DELETED 10-MAR-19