Solved

Ms Access Query - Can this query be redesigned to provide summary data only

Posted on 2014-01-02
4
309 Views
Last Modified: 2014-01-02
The query below produces enrollment data for every grade in the school for a given year.  I would like to create a query that provides just a total enrollment number per school for the given year.  The current query when parameters are applied produces the following as an example:

School A for a certain year
Grade 6 100
Grade 7 100
Grade 8 100

I have a report that sums the totals and compares them.  I would like a query that does the summing for use in other reports.  For example when the year parameters are applied I just want the total as below.

School A 300

My current sql follows

SELECT enrollment.er_school_id, Sum(IIf([Year]=forms!select_dates!current_year,[enroll_data],0)) AS [Current Enrollment], Sum(IIf([Year]=forms!select_dates!proposed_year,[enroll_data],0)) AS [Proposed Enrollment], ([Proposed Enrollment]-[Current Enrollment]) AS [+/- Enrollment], enrollment.enroll_desc, enrollment.erdisplay_order, schools.schoollName, schools.school_id, Enroll_gradeNames.dgrdisplay_order, schools.Type
FROM schools INNER JOIN (enrollment LEFT JOIN Enroll_gradeNames ON enrollment.enroll_desc = Enroll_gradeNames.Grade_name) ON schools.school_id = enrollment.er_school_id
WHERE (((schools.open_date)<="forms]![select_dates]![current_year]") AND ((schools.close_date)>=[forms]![select_dates]![proposed_year]))
GROUP BY enrollment.er_school_id, enrollment.enroll_desc, enrollment.erdisplay_order, schools.schoollName, schools.school_id, Enroll_gradeNames.dgrdisplay_order, schools.Type;

Open in new window

0
Comment
Question by:Sbovino
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 167 total points
ID: 39751632
copy your above query and save with a different name
modify the new query by removing the table "Enroll_gradeNames"

see if you come out with the result you want.


if the query did not return the  desired result, it will help if you can upload a copy of the db  with the relevant forms and tables.
0
 
LVL 12

Accepted Solution

by:
pdebaets earned 167 total points
ID: 39751639
Try this:

SELECT enrollment.er_school_id, Sum(IIf([Year]=forms!select_dates!current_year,[enroll_data],0)) AS [Current Enrollment], Sum(IIf([Year]=forms!select_dates!proposed_year,[enroll_data],0)) AS [Proposed Enrollment], ([Proposed Enrollment]-[Current Enrollment]) AS [+/- Enrollment],  schools.schoollName, schools.school_id
FROM schools INNER JOIN (enrollment LEFT JOIN Enroll_gradeNames ON enrollment.enroll_desc = Enroll_gradeNames.Grade_name) ON schools.school_id = enrollment.er_school_id
WHERE (((schools.open_date)<="forms]![select_dates]![current_year]") AND ((schools.close_date)>=[forms]![select_dates]![proposed_year]))
GROUP BY enrollment.er_school_id,   schools.schoollName, schools.school_id;

Open in new window

0
 
LVL 48

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 166 total points
ID: 39751701
I don't think there is any need to change the query at all.  So what you have is a report that looks something like:

School A
    6th Grade  100
    7th Grade  100
    8th Grade  100
School B
    6th Grade  120
    7th Grade    98
    8th Grade  110

If that is correct, and you are grouping by school with the grade counts in the details section, you could set the detail sections Visible property to false (or make the height = zero), and move the school info from the Group Header (set that height to zero) to the Group Footer.  So in the Group Footer you would have two fields:

School Name        Enrollment
School A                  300
School B                  328

For the total enrollment, you would use the following as the control source for that textbox located in the group footer.

= Sum([Enrollment])
0
 

Author Closing Comment

by:Sbovino
ID: 39752024
All options presented worked.  Thank you.  For some reason i could not see how simple this was to do.   Happy New Year!
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

729 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