Solved

Specified Expression not included as part of aggregate Function

Posted on 2006-11-13
6
284 Views
Last Modified: 2008-02-01
Hello,

I have a database with Prioperties (PropertyID) and Years.  

I am trying to build a query that will give me the Sum of the RoomsCoorExp + FBExp for each Property.  I've got that part working fine.  I don't want to include any of the RoomsCorrExp or FB Exp if the GrossRevenue = 0 for that particular year.

I tried entering [GrossRevenues]<>0 as the criteria for my expression, and I get the Error "You tried to execute a query that does not include the specified expression 'Not [GrossRevenues]=0' as part of an aggregate function.

The SQL that does work (before I try to add in the GrossRevenue critearia) is:
SELECT tblFinancial.PropertyID, tblMASTER.HotelName, Sum([tblFinancial].[RoomsCorrExp]+[tblFinancial].[FBExp]) AS TotalCapEx
FROM tblFinancial INNER JOIN tblMASTER ON tblFinancial.PropertyID = tblMASTER.PropertyID
GROUP BY tblFinancial.PropertyID, tblMASTER.HotelName;

Any thoughts?

Thanks!
cdmac
0
Comment
Question by:cdmac2
  • 2
  • 2
  • 2
6 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17933447
An alternative way, try this
though it might still complain due to +

SELECT tblFinancial.PropertyID, tblMASTER.HotelName, Sum([tblFinancial].[RoomsCorrExp])+Sum([tblFinancial].[FBExp]) AS TotalCapEx
FROM tblFinancial INNER JOIN tblMASTER ON tblFinancial.PropertyID = tblMASTER.PropertyID
GROUP BY tblFinancial.PropertyID, tblMASTER.HotelName
0
 
LVL 1

Author Comment

by:cdmac2
ID: 17933547
Rockiroads,

Thanks for your response.  The Statment I wrote above DOES work (I tried your statement too, and it also works).  What I can't figure out how to do is get the "GrossRevenues<>0" Criteria in there.

Thx!
0
 
LVL 44

Accepted Solution

by:
GRayL earned 500 total points
ID: 17933607
SELECT tblFinancial.PropertyID, tblMASTER.HotelName, Sum([tblFinancial].[RoomsCorrExp])+Sum([tblFinancial].[FBExp]) AS TotalCapEx
FROM tblFinancial INNER JOIN tblMASTER ON tblFinancial.PropertyID = tblMASTER.PropertyID
WHERE <WhichTable?>.GrossRevenues <> 0
GROUP BY tblFinancial.PropertyID, tblMASTER.HotelName;

Add the third line and be sure to replace <WhichTable?> with the correct table name - either tblFinancial or tblMaster
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 65

Expert Comment

by:rockiroads
ID: 17933654
ok, gotcha
I see GRayL has given u the answer, obviously too slow in responding today
I think it has something to do with tree cutters!

0
 
LVL 1

Author Comment

by:cdmac2
ID: 17933679
Worked like a charm!

I'm feeling a little off myself.  The solution was very simple.. for some reason I was stuck in the HAVING statemnt.

Thanks guys!


0
 
LVL 44

Expert Comment

by:GRayL
ID: 17933746
Thanks, glad I could help.  

rocki, the vision is slowly improving.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now