473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Join Issue

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

Nov 13 '05 #1
5 1120
I can't think of a way to do this with pure SQL (I played with putting
the 3 possible statuses into a table and using outer joins).

What you could do is write code to copy the data you needed into a
temporary table and query from that. That way, you could direct the
code to write out zeros where it makes sense.

Sorry, I know this isn't much help.

Johnny

Nov 13 '05 #2
Johnny,

I tried the table and outer joins also. One would think that shoud
work.

I was doing the code, but figured there was an easier way through
queries.

Thanks!

-Brian

Nov 13 '05 #3
is 'applicationStatus' a table ?
if so, don't use any joins in your query, ie.

select tblAgency.agency, tblApplicationStatus.applicationStatus, 0 as
appCount
from tblAgency, tblApplicationStatus

this will give you a 'cartesian product', ie all combinations of agency
and status

now use this query (ie. qryAll) in a union query with your original
query
ie

select * from qryAll
union
select * from yourQuery

should get all agencies, all status with the correct count

Nov 13 '05 #4
Sure. Create a table or query that has Paid, Declined, Reopened in the
recordset (just 3 records, so you may need a DISTINCT clause). then
you can left join that to your normal table, and then group by agency
and application status. the outer join - show all records from the
Paid, Declined, Reopened table/query, and then the matching ones from
the table you have.

Nov 13 '05 #5


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

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: Leo Breebaart | last post by:
I've tried Googling for this, but practically all discussions on str.join() focus on the yuck-ugly-shouldn't-it-be-a-list-method? issue, which is not my problem/question at all. What I can't...
0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
2
by: dskillingstad | last post by:
I would really appreciate someone's help on this, or at least point me in the right direction.... I'm working on a permit database that contains 12 tables, and rather than list all of the...
14
by: Bob | last post by:
I have a function that takes in a list of IDs (hundreds) as input parameter and needs to pass the data to another step as a comma delimited string. The source can easily create this list of IDs in...
33
by: Steve | last post by:
One of our clients recently upgraded their Office version to 2003. When they tried to run our program (written in Access 2000), they ended up with the wrong data. My coworker and I have tested this...
14
by: Joe | last post by:
Does anyone know the difference, in practical terms, between Thread.Sleep (10000) and Thread.CurrentThread.Join (10000)?? The MSDN says that with Join, standard COM and SendMessage pumping...
7
by: dunleav1 | last post by:
I have an application that uses the old join syntax instead of the SQL92 standards join syntax. I need to justify changing the code to the new standard. Is there any performance issue related to...
2
by: headache | last post by:
Greetings. I'm a first time poster, so feel free to clue me in to any protocol I may have inadvertently violated. I have an issue that has arisen where I need to join 3 tables where 2 of the 3...
3
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central table (tblMaster)... I want to perform a query, so...
1
by: nmailey | last post by:
Hi all. Here's what I'm encountering in SQL 2000. I've got the following tables: program ------------ id (pk int) program_component_type_rel ------------
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.