Solved

Help with ms access query

Posted on 2014-04-14
9
318 Views
Last Modified: 2014-04-14
Hi, experts.
I have a simple database.
I have two queries:
qryRec_Last---------------shows how many projects received
qryPro_Last---------------shows how many projects completed

select Count(qryRec_Last_1.projectId) AS Count FROM qryRec_Last_1
------->60
select Count(qryPro_Last_1.projectId) AS FROM qryPro_Last_1;
------->30

i want to write a query showing:
Received             Completed           %
60                        30                        50%

Thanks
0
Comment
Question by:rfedorov
9 Comments
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 50 total points
ID: 39999272
Are they stored queries?

If so, then create a third, and include those two in the query design, and join them on the appropriate field if needed.

Now create another field that calculates them:

CompletePct: qryRec_Last_1.Count / qryPro_Last_1.Count

Note that you have NOT used an alias in qryPro_Last_1, so you'd need to do that:

select Count(qryPro_Last_1.projectId) AS Count FROM qryPro_Last_1;
0
 

Author Comment

by:rfedorov
ID: 39999300
Thank you for the fast respond, but i did not get ... I do not have a proble with calculating the %, i can not figure out how to put them on the same line:
Received             Completed           %
60                        30                        50%
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39999392
what is the name of the table where based your two queries?

post the sql of the two queries.
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:rfedorov
ID: 39999403
select Count(qryRec_Last_1.projectId) AS Count FROM qryRec_Last_1
select Count(qryPro_Last_1.projectId) AS FROM qryPro_Last_1;
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39999524
what is the name of the table where based your two queries?

post the sql of the two queries.  
"qryRec_Last_1"

"qryPro_Last_1"
0
 

Author Comment

by:rfedorov
ID: 39999550
' qryPro_Last_1
SELECT
DISTINCT DataExtr.StatusCreatedByUser, DataExtr.StartStatus, DataExtr.EndStatus, DataExtr.StartDate, DataExtr.projectId, Format([StartDate],"mm/dd/yyyy") AS DatePortion
FROM DataExtr
WHERE (((DataExtr.StatusCreatedByUser) In ("GR","Cs","Jr")) AND ((DataExtr.StartStatus)="15 - Project Completion") AND ((DataExtr.EndStatus)="Invoice Approved") AND ((Format([StartDate],"mm/dd/yyyy")) Between "01/06/2014" And "01/10/2014") AND ((Format([StartDate],"yyyy"))="2014"))
ORDER BY DataExtr.StartDate, DataExtr.projectId;



'qryRec_Last_1
SELECT DataExtr.projectId, DataExtr.EndStatus, TimeValue([StartDate]) AS [Time], DataExtr.StartDate, IIf(TimeValue([StartDate])<=#12/30/1899 15:0:0#,[StartDate],DateAdd("h",12,[StartDate])) AS New, Format([StartDate],"mm/dd/yyyy") AS JustDate
FROM DataExtr
WHERE (((DataExtr.EndStatus)="06a - Implementer Verified Measures") AND ((Format([StartDate],"mm/dd/yyyy")) Between "01/02/2014" And "01/10/2014"))
ORDER BY DataExtr.projectId, DataExtr.StartDate DESC;
0
 
LVL 27

Assisted Solution

by:skullnobrains
skullnobrains earned 50 total points
ID: 39999560
select
  (select Count(qryRec_Last_1.projectId) AS Count FROM qryRec_Last_1) as received
  ,(select Count(qryPro_Last_1.projectId) AS FROM qryPro_Last_1) as completed
  completed * 100 / received & ' %' as percentage
0
 

Author Comment

by:rfedorov
ID: 39999668
If i copy exactly what you put, i am getting the error...
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 400 total points
ID: 39999705
try this query



Select sum(iif(A.[Source]="Rec",1,0)) as Received, sum(iif(A.[Source]="Pro",1,0)) as Completed,
([Received]/[Completed]) as CompletePct
From
(
select [projectId], 'Pro' as Source from qryPro_Last_1
Union all
select [projectId], 'Rec' as Source from qryRec_Last_1
) as A
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question