SELECT tblApprovals.AccountID, tblAccounts.AccountNumber, tblAccounts.AccountName, tblBanks.BankName, tblCurrencies.Ccy, tblEntities.Entity, tblSubGroups.SubGroup, tblFundingPartners.FundingPartner, tblFundingRoles.FundingRole, tblApprovals.Reject, tmp.Pending
FROM (((((((tblApprovals
LEFT JOIN tblAccounts ON tblApprovals.AccountID = tblAccounts.AccountID)
LEFT JOIN tblBanks ON tblAccounts.BankID = tblBanks.BankID)
LEFT JOIN tblCurrencies ON tblAccounts.CcyID = tblCurrencies.CcyID) LEFT JOIN tblEntities ON tblAccounts.EntityID = tblEntities.EntityID)
LEFT JOIN tblFundingPartners ON tblAccounts.FundingPartnerID = tblFundingPartners.FundingPartnerID)
LEFT JOIN tblFundingRoles ON tblAccounts.FundingRoleID = tblFundingRoles.FundingRoleID)
LEFT JOIN tblSubGroups ON tblAccounts.SubGroupID = tblSubGroups.SubGroupID)
LEFT JOIN
[COLOR=black] (SELECT tblApprovals.AccountID, Count(tblApprovals.ApprovalID) AS Pending[/COLOR]
[COLOR=black] FROM tblApprovals[/COLOR]
[COLOR=black] WHERE tblApprovals.Reject = False[/COLOR]
[COLOR=black] GROUP BY tblApprovals.AccountID) AS tmp [/COLOR]
[COLOR=black] ON tblApprovals.AccountID = tmp.AccountID[/COLOR]
GROUP BY tblApprovals.AccountID, tblAccounts.AccountNumber, tblAccounts.AccountName, tblBanks.BankName, tblCurrencies.Ccy, tblEntities.Entity, tblSubGroups.SubGroup, tblFundingPartners.FundingPartner, tblFundingRoles.FundingRole, tblApprovals.Reject, [COLOR=black]tmp.Pending[/COLOR]
HAVING (((tblApprovals.Reject)=False))