Well, you need to GROUP BY the expression also.
SELECT [Eval Data - Instructor].LastName
, [Eval Data - Instructor].Course
, [Eval Data - Instructor].Section
, [Eval Data - Instructor].StartDate
, Class.Cost, Class.CostAdjust
, Class.CurrentEnrollment
, IIf([State]="Delivery",([Cost]+[CostAdjust])*[CurrentEnrollment]
,([Cost]+[CostAdjust])*[CurrentEnrollment]/2) AS [Class Cost]
FROM Class INNER JOIN [Eval Data - Instructor]
ON Class.Section = [Eval Data - Instructor].Section
GROUP BY [Eval Data - Instructor].LastName
, [Eval Data - Instructor].Course
, [Eval Data - Instructor].Section
, [Eval Data - Instructor].StartDate
, Class.Cost, Class.CostAdjust
, Class.CurrentEnrollment
, , IIf([State]="Delivery",([Cost]+[CostAdjust])*[CurrentEnrollment]
,([Cost]+[CostAdjust])*[CurrentEnrollment]/2)
ORDER BY [Eval Data - Instructor].LastName;
HOWEVER since you are not using any of the aggregate functions such as
Sum, Count, Avg, etc. you can simplify the query by using the DISTINCT
operation. In Design view, use the query's unique values property and
set it to Yes. (In Design view, Right-Click in any empty field box and
select properties to get to the query's properties)
SELECT DISTINCT [Eval Data - Instructor].LastName
, [Eval Data - Instructor].Course
, [Eval Data - Instructor].Section
, [Eval Data - Instructor].StartDate
, Class.Cost, Class.CostAdjust
, Class.CurrentEnrollment
, IIf([State]="Delivery",([Cost]+[CostAdjust])*[CurrentEnrollment]
,([Cost]+[CostAdjust])*[CurrentEnrollment]/2) AS [Class Cost]
FROM Class INNER JOIN [Eval Data - Instructor]
ON Class.Section = [Eval Data - Instructor].Section
ORDER BY [Eval Data - Instructor].LastName;
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
John, Here is the SQL.....
SELECT [Eval Data - Instructor].LastName, [Eval Data - Instructor].Course,
[Eval Data - Instructor].Section, [Eval Data - Instructor].StartDate,
Class.Cost, Class.CostAdjust, Class.CurrentEnrollment,
IIf([State]="Delivery",([Cost]+[CostAdjust])*[CurrentEnrollment],([Cost]+[CostAdjust])*[CurrentEnrollment]/2) AS [Class Cost]
FROM Class INNER JOIN [Eval Data - Instructor] ON Class.Section = [Eval Data
- Instructor].Section
GROUP BY [Eval Data - Instructor].LastName, [Eval Data - Instructor].Course,
[Eval Data - Instructor].Section, [Eval Data - Instructor].StartDate,
Class.Cost, Class.CostAdjust, Class.CurrentEnrollment
ORDER BY [Eval Data - Instructor].LastName;
The error message I received is......"You tried to execute a query that did
not include the specified expression
'IIf([State]="Delivery",([Cost]+[CostAdjust])+[CurrentEnrollment],([Cost]+[CostAdjust])*[CurrentEnrollment]/2)' as part of an aggregate function"
Thank you for any assistance you can give me!!!
John Spencer said:
POST the SQL of the query you are having a problem with AND the text of
the error message.
(Menu: VIEW: SQL when in design view)
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================