SELECT /*Account info*/ AT.cAccountTypeDescription ,A.Master_Sub_Account ,A.Description /*Allocated info*/ ,PAP.PercentagePaid ,TotalPaidAmount = COALESCE(PAP.PercentagePaid,1) * (T.Debit-T.Credit) /*Tx info:*/ ,T.* /*IDs and other:*/ ,A.AccountLink FROM _bvGLTransactionsFull T LEFT JOIN Accounts A ON T.AccountLink = A.AccountLink LEFT JOIN _etblGLAccountTypes AT ON A.iAccountType = AT.idGLAccountType LEFT JOIN (SELECT P.cAuditNumber, ROUND((ABS(SUM(Debit-Credit))- ABS(SUM(P.Outstanding))) / ABS(SUM(Debit-Credit)),4) as PercentagePaid ,SUM(Debit-Credit) as DmC, SUM(P.Outstanding) as Outstanding FROM PostAP P GROUP BY P.cAuditNumber) PAP ON T.cAuditNumber = PAP.cAuditNumber