Aggregate Funcation

M

margaret

I'm confused. When I try to execute the following query:

SELECT tblSales.game, tblSales.fairdate, tblSales.amount, tblSales.cash,
tblSales.ctrlyear, tblSales.DAYOFFAIR, gamemaster.gname,
IIf([CTRLYEAR]=[First Year?],Sum([amount])) AS currentamt,
IIf([CTRLYEAR]=[Second Year?],Sum([amount])) AS previousamt
FROM gamemaster INNER JOIN tblSales ON gamemaster.game = tblSales.game;

I get this message:

You tried to execute a query that does not include the specified expression
'game' as a part of an aggregate function. However, if I remove the
"currentamt" and the "previousamt", the query will work? Why?

Thanks for any help.
 
K

Keith Wilby

margaret said:
I'm confused. When I try to execute the following query:

SELECT tblSales.game, tblSales.fairdate, tblSales.amount, tblSales.cash,
tblSales.ctrlyear, tblSales.DAYOFFAIR, gamemaster.gname,
IIf([CTRLYEAR]=[First Year?],Sum([amount])) AS currentamt,
IIf([CTRLYEAR]=[Second Year?],Sum([amount])) AS previousamt
FROM gamemaster INNER JOIN tblSales ON gamemaster.game = tblSales.game;

I get this message:

You tried to execute a query that does not include the specified
expression
'game' as a part of an aggregate function. However, if I remove the
"currentamt" and the "previousamt", the query will work? Why?

Thanks for any help.

Is "gname" a typo or a mistake in your query?

Keith.
 
M

margaret

Neither ... gname is actually a field (It stands for game name)

Keith Wilby said:
margaret said:
I'm confused. When I try to execute the following query:

SELECT tblSales.game, tblSales.fairdate, tblSales.amount, tblSales.cash,
tblSales.ctrlyear, tblSales.DAYOFFAIR, gamemaster.gname,
IIf([CTRLYEAR]=[First Year?],Sum([amount])) AS currentamt,
IIf([CTRLYEAR]=[Second Year?],Sum([amount])) AS previousamt
FROM gamemaster INNER JOIN tblSales ON gamemaster.game = tblSales.game;

I get this message:

You tried to execute a query that does not include the specified
expression
'game' as a part of an aggregate function. However, if I remove the
"currentamt" and the "previousamt", the query will work? Why?

Thanks for any help.

Is "gname" a typo or a mistake in your query?

Keith.
 
D

Duane Hookom

You can't use a SUM() without a GROUP BY in the SQL statement.

It looks like you are attempting to display both detailed and aggregate
information. Typically you will display the aggregates in a report footer
section using the expression Marsh suggested to you in a previous thread. You
never replied to Marsh's most recent post.

Do you really need summary and detail information in the query?

--
Duane Hookom
Microsoft Access MVP


margaret said:
Neither ... gname is actually a field (It stands for game name)

Keith Wilby said:
margaret said:
I'm confused. When I try to execute the following query:

SELECT tblSales.game, tblSales.fairdate, tblSales.amount, tblSales.cash,
tblSales.ctrlyear, tblSales.DAYOFFAIR, gamemaster.gname,
IIf([CTRLYEAR]=[First Year?],Sum([amount])) AS currentamt,
IIf([CTRLYEAR]=[Second Year?],Sum([amount])) AS previousamt
FROM gamemaster INNER JOIN tblSales ON gamemaster.game = tblSales.game;

I get this message:

You tried to execute a query that does not include the specified
expression
'game' as a part of an aggregate function. However, if I remove the
"currentamt" and the "previousamt", the query will work? Why?

Thanks for any help.

Is "gname" a typo or a mistake in your query?

Keith.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top