BerkshireGuy wrote:
Here is the problem I am having:
In a table I have the following fields:
Agency
ApplicationStatus
CountOfApplications
There are several application status: Paid, Declined, Reopened
Sometimes, an agency can have all three records, Paid, Declined or
Reopened. Or sometmes it may just have a Decline record.
What I am trying to do is return all three status (Paid,Declined,
Reopened) with their countofapplications. If one of the status isnt
there, then return the Status Name (Paid,Declined, Reopened) and the 0
for a count.
Any ideas?
Thanks
The first idea I had was to try subqueries. I don't know if the result
is what you are looking for but perhaps it will give you some ideas.
You've probably solved it by now anyway.
tblApplications
ApplicationID AgencyID ApplicationStatus
1 1 Paid
2 1 Declined
3 1 Reopened
4 2 Paid
5 2 Declined
6 3 Declined
7 3 Reopened
8 4 Reopened
qryCountPaidDeclinedReopened:
SELECT AgencyID, (SELECT COUNT(tblApplications.AgencyID) FROM
tblApplications AS A WHERE A.AgencyID = tblApplications.AgencyID AND
A.ApplicationStatus="Paid") AS PaidCount, (SELECT
COUNT(tblApplications.AgencyID) FROM tblApplications AS A WHERE
A.AgencyID = tblApplications.AgencyID AND
A.ApplicationStatus="Declined") AS DeclinedCount, (SELECT
COUNT(tblApplications.AgencyID) FROM tblApplications AS A WHERE
A.AgencyID = tblApplications.AgencyID AND
A.ApplicationStatus="Reopened") AS ReopenedCount FROM tblApplications
GROUP BY AgencyID;
! qryCountPaidDeclinedReopened:
AgencyID PaidCount DeclinedCount ReopenedCount
1 1 1 1
2 1 1 0
3 0 1 1
4 0 0 1
James A. Fortune