By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,696 Members | 1,424 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,696 IT Pros & Developers. It's quick & easy.

ADO Vs Jet/DAO for compound aggregate function

P: n/a
I just wasted a long time figuring out this and I figure if I post it
might save someone some pain!

Jet (DAO) will allow you to to use nested aggregate functions like
building blocks, e.g.:

SELECT
A,
sum(B) as Answer1,
Answer1 * 2 as DoubleAnswer
From
Table
GROUP BY
A;

If you save this query and run it from ADO
(e.g. ADORecordset.Open "qrySavedQuery", myConnection) you will get:

You tried to execute a query that does not include the specified
expression 'Answer1 * 2' as part of an aggregate function.

Yet opening the saved query normally or calling it from DAO will work
fine.

ADO requires you to write the query like this:

SELECT
A,
sum(B) as Answer1,
sum(B) * 2 as DoubleAnswer
From
Table
GROUP BY
A;

i.e. an aggregate function cannot refer to another aggregate function
in the same query.

Anyone else found this, or am I mis-reading cause and effect of problem
here?

Nov 9 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
bas
Hello BillCo,

You have to change the group by in ADO to:

GROUP BY
A,
Answer1 * 2 as DoubleAnswer

Regards,
Bas
I just wasted a long time figuring out this and I figure if I post it
might save someone some pain!

Jet (DAO) will allow you to to use nested aggregate functions like
building blocks, e.g.:

SELECT
A,
sum(B) as Answer1,
Answer1 * 2 as DoubleAnswer
From
Table
GROUP BY
A;
If you save this query and run it from ADO
(e.g. ADORecordset.Open "qrySavedQuery", myConnection) you will get:
You tried to execute a query that does not include the specified
expression 'Answer1 * 2' as part of an aggregate function.

Yet opening the saved query normally or calling it from DAO will work
fine.

ADO requires you to write the query like this:

SELECT
A,
sum(B) as Answer1,
sum(B) * 2 as DoubleAnswer
From
Table
GROUP BY
A;
i.e. an aggregate function cannot refer to another aggregate function
in the same query.

Anyone else found this, or am I mis-reading cause and effect of
problem here?

Nov 9 '06 #2

P: n/a
I tried that, as it seemed the obvious answer - and no joy... same
failure notice. the only thing that worked was to not use compound
aggregates; to break down the formula to field level. (Or to use a
subquery)
bas wrote:
Hello BillCo,

You have to change the group by in ADO to:

GROUP BY
A,
Answer1 * 2 as DoubleAnswer

Regards,
Bas
I just wasted a long time figuring out this and I figure if I post it
might save someone some pain!

Jet (DAO) will allow you to to use nested aggregate functions like
building blocks, e.g.:

SELECT
A,
sum(B) as Answer1,
Answer1 * 2 as DoubleAnswer
From
Table
GROUP BY
A;
If you save this query and run it from ADO
(e.g. ADORecordset.Open "qrySavedQuery", myConnection) you will get:
You tried to execute a query that does not include the specified
expression 'Answer1 * 2' as part of an aggregate function.

Yet opening the saved query normally or calling it from DAO will work
fine.

ADO requires you to write the query like this:

SELECT
A,
sum(B) as Answer1,
sum(B) * 2 as DoubleAnswer
From
Table
GROUP BY
A;
i.e. an aggregate function cannot refer to another aggregate function
in the same query.

Anyone else found this, or am I mis-reading cause and effect of
problem here?
Nov 10 '06 #3

P: n/a
BillCo wrote:
I just wasted a long time figuring out this and I figure if I post it
might save someone some pain!

Jet (DAO) will allow you to to use nested aggregate functions like
building blocks, e.g.:

SELECT
A,
sum(B) as Answer1,
Answer1 * 2 as DoubleAnswer
From
Table
GROUP BY
A;

If you save this query and run it from ADO
(e.g. ADORecordset.Open "qrySavedQuery", myConnection) you will get:

You tried to execute a query that does not include the specified
expression 'Answer1 * 2' as part of an aggregate function.

Yet opening the saved query normally or calling it from DAO will work
fine.

ADO requires you to write the query like this:

SELECT
A,
sum(B) as Answer1,
sum(B) * 2 as DoubleAnswer
From
Table
GROUP BY
A;

i.e. an aggregate function cannot refer to another aggregate function
in the same query.

Anyone else found this, or am I mis-reading cause and effect of problem
here?
Are you comparing apples to apples and oranges to oranges?

Did you try running the query in both ADO and DAO as a saved query?

Did you try running the query in both ADO and DAO as a query string?

When I test stored queries against stored queries I get the same
result: success.

When I test query strings against query strings I get the same results:
the error you describe.

Nov 10 '06 #4

P: n/a
Lyle,

the query was always saved as a standard jet mdb query (a2k)
it always ran fine from the ms access user interface.

However
dim rst as adodb.recordset
rst.open "qryCompoundAggregate", cnCurrentConnection
yields the error I reported.

I presumed (perhaps wrongly) that it was down to a difference in how
ADO handles the query's SQL syntax as opposed to Jet. Here's where I'm
hazy though - does ADO read the saved SQL and do it's own data-mining,
or does Jet serve the data regardless of what data language is used?
the fact that saved queries with * wildcards are rejected by ADO would
suggest the former.

I havent tested with a DAO recordset. So you are probably correct -
apples and oranges. I'll check it out.
Are you comparing apples to apples and oranges to oranges?

Did you try running the query in both ADO and DAO as a saved query?

Did you try running the query in both ADO and DAO as a query string?

When I test stored queries against stored queries I get the same
result: success.

When I test query strings against query strings I get the same results:
the error you describe.
Nov 10 '06 #5

P: n/a
bas
Hello BillCo,

I think I see the problem.
In your query you are referring to another calculated field, I think that
is causing the problem.
Field DoubleAnswer should make it's own calculation and not be based on another
calculated field in the same query.

So, if you rewrite the query like this, it will work:

SELECT
A,
sum(B) as Answer1,
sum(B)* 2 as DoubleAnswer
From
Table
GROUP BY
A;

Regards,
Bas
I tried that, as it seemed the obvious answer - and no joy... same
failure notice. the only thing that worked was to not use compound
aggregates; to break down the formula to field level. (Or to use a
subquery)

bas wrote:
>Hello BillCo,

You have to change the group by in ADO to:

GROUP BY
A,
Answer1 * 2 as DoubleAnswer
Regards,
Bas
>>I just wasted a long time figuring out this and I figure if I post
it might save someone some pain!

Jet (DAO) will allow you to to use nested aggregate functions like
building blocks, e.g.:

SELECT
A,
sum(B) as Answer1,
Answer1 * 2 as DoubleAnswer
From
Table
GROUP BY
A;
If you save this query and run it from ADO
(e.g. ADORecordset.Open "qrySavedQuery", myConnection) you will get:
You tried to execute a query that does not include the specified
expression 'Answer1 * 2' as part of an aggregate function.
Yet opening the saved query normally or calling it from DAO will
work fine.

ADO requires you to write the query like this:

SELECT
A,
sum(B) as Answer1,
sum(B) * 2 as DoubleAnswer
From
Table
GROUP BY
A;
i.e. an aggregate function cannot refer to another aggregate
function
in the same query.
Anyone else found this, or am I mis-reading cause and effect of
problem here?

Nov 10 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.