SELECT pmt.[Entry No_] , inv.[Document No_] , d_inv.Amount , sil.[Line No_] FROM dbo.[<Company>$Cust_ Ledger Entry] pmt -- payment entries INNER JOIN dbo.[<Company>$Detailed Cust_ Ledg_ Entry] d_inv ON d_inv.[Applied Cust_ Ledger Entry No_] = pmt.[Entry No_] -- invoice detail lines where payment is applied to invoice INNER JOIN dbo.[<Company>$Cust_ Ledger Entry] inv ON inv.[Entry No_] = d_inv.[Cust_ Ledger Entry No_] -- invoice entries INNER JOIN dbo.[<Company>$Sales Invoice Line] sil ON sil.[Document No_] = inv.[Document No_] WHERE pmt.[Document Type] = 1-- payment doc type AND inv.[Document Type] = 2 -- invoice doc type AND d_inv.[Unapplied] = 0 -- not unapplied
Answers