• Modifying the second join to:

    [font="Courier New"]

    Inner JOIN InvoiceDetailAfter A on A.InvoiceId= I.id AND A.TxnLineID = B.TxnLineID

    [/font]

    Solved the problem. Thank you!