I am wondering if this is possible.
I have a table that has install and order data and another table that has rep data
I have 1 query that joins the install Id and order Id to the rep data table. If both install and order id match the reps id then it is marked with an OI
This query appends to a table with the primary key set to Order number
I have a second query that matches on install Id to the rep data table. If it matches it is marked with an I
This appends to the table above and the records already set to OI get ignored
I have a third query that matches on order Id to the rep data table. If it matches it is marked with an O
This appends to the table above and the records already set to OI get ignored
The OIs go into the table first because this is where the rep is both order and install rep works fine. My issue us when the order rep and the install rep are different but both reps are in the rep table. They will not be loaded as an OI in the first step. The install rep will be appended as an I but then the Order Rep will not get appended because the order number already exists in the table as an I. If I add revenue type (OI,O,I) to the primary key I get I and O records and I records, as well as OI records for those orders where the order and install rep are the same.
Is there a way to say append the O and I data if there is no OI data already in the table? Having brain freeze.
Hope this isn't too confusing
Thanks in advance for the help.