Re: error message.
- From: "John Spencer (MVP)" <spencer@xxxxxxxxx>
- Date: Tue, 20 Jan 2009 08:50:39 -0500
Since you are using one of the aggregate functions (SUM) in the query, you need to group by all of the other fields that are not using the sum function.
SELECT [activity table].time
, [activity table].ID
, [activity table].patient
, [activity table].activity
, [activity table].[reason for cancellation]
, [activity table].Dept
, [activity table].Staff
, [activity table].Datein
, [activity table].Ward
, [activity table].cost
, [activity table].xtrstaff
, IIf([activity]="court apperance",30,0) AS extra
, IIf([reason for cancellation]>"",0, Sum(([xtrstaff]*([time]/60))))+
Sum(IIf([activity]="court appearance",30,0))) AS xtrcost
FROM [activity table]
GROUP BY [activity table].time
, [activity table].ID
, [activity table].patient
, [activity table].activity
, [activity table].[reason for cancellation]
, [activity table].Dept
, [activity table].Staff
, [activity table].Datein
, [activity table].Ward
, [activity table].cost
, [activity table].xtrstaff
, IIf([activity]="court apperance",30,0)
I would probably be testing [reason for cancellation] to be not null instead of checking to see if it is a zero length string. (Or perhaps, you need to check for both as follows)
IIF([Reason for Cancellation] & "" = "", ...
All that said, I'm not sure that this query is going to give you the desired result even if you do get it to work. You might need to replace the SUM with the VBA function DSUM or with a subquery in the Select clause; and drop the entire Group by clause.
Perhaps you can explain what you are trying to do with the expression:
, IIf([reason for cancellation]>"", 0, (Sum(([xtrstaff]*([time]/60))))+
Sum(IIf([activity]="court appearance",30,0))) AS xtrcost
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
steve a wrote:
Hi i'm stuggling with this error message and don't understand how to get around it..
the error reads:
"you tried to execute a query that does not includde the expression 'time' as part of an aggregate function."
SELECT[activity table].time, [activity table].ID, [activity table].patient, [activity table].activity, [activity table].[reason for cancellation], [activity table].Dept, [activity table].Staff, [activity table].Datein, [activity table].Ward, [activity table].cost, [activity table].xtrstaff, IIf([activity]="court apperance",30,0) AS extra, IIf([reason for cancellation]>"",0,(Sum(([xtrstaff]*([time]/60))))+Sum(IIf([activity]="court appearance",30,0))) AS xtrcost
FROM [activity table];
the complete SQL is as follows
- Follow-Ups:
- Re: error message.
- From: steve a
- Re: error message.
- References:
- error message.
- From: steve a
- error message.
- Prev by Date: Re: do a query based on a text box with data or empty text box
- Next by Date: Re: Updating records that may not need updating
- Previous by thread: Re: error message.
- Next by thread: Re: error message.
- Index(es):
Relevant Pages
|
Loading