I have an invoice detail table that I need to pull two fields from and put into another table.Is there a way to pull distinct fields from that table so that there are no duplicates inserted into the destination table?Here's an example of the dataInvDet Table (Invoice Detail Table)INV_NO - PART_NO - GL_NO - CO_NO 1 ______ 123 _____ 900 ____ 001 1 ______ 111 _____ 900 ____ 001 2 ______ 111 _____ 901 ____ 001 2 ______ 123 _____ 901 ____ 001 2 ______ 999 _____ 902 ____ 001Here's what I need to end up with LogInv Destination tableINV_NO - CO_NO 1 ______ 001 2 ______ 001The catch is the destination table is being populated via a trigger on the detail table. The GL_NO is originally set to 0, when it's given a value(not 0), then I need the trigger to pull the INV_NO and CO_NO into the destination table. But only one line per INV_NO. Here's what I have so far, right now it will insert duplicates. INSERT INTO LogInv (inv_no, co_no, action, hdr_processed_flag, dtl_processed_flag ) SELECT inv_no, co_no , 'I', 0, 0 FROM inserted WHERE GL_NO > 0 AND inv_no in (Select inv_no from DELETED where GL_NO = 0)
Keep in mind this statement is executed inside an UPDATE trigger.