473,721 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ADO Vs Jet/DAO for compound aggregate function

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.Op en "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
5 6096
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.Op en "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
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.Op en "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
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.Op en "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
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 "qryCompoundAgg regate", cnCurrentConnec tion
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
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.Op en "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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2257
by: sausage31 | last post by:
I have a table as follows.... Device LotID Result1 Result2 Result3 aaa 1 5 10 15 bbb 1 2 4 6 aaa 2 3 6 9 I need to determine the mean of all results for each LotID, so used the Row Average function described on the Microsoft Knowledge base, which gives
10
11933
by: neb | last post by:
Dear member of the forum, Ms access has built-in aggregate function like: -Sum, Max, First, Avg, ... Is it possible to build user-defined aggregate? (if you have any clue, do not hesitate to post) *I'm running a total query, of the form
7
1934
by: Eric Laberge | last post by:
Aloha! This question is meant to be about C99 and unnamed compound objects. As I read, if such a construct as int *p = (int){0}; is used within a function, then it has "automatic storage duration associated with the enclosing block". So I tried the annexed code, and it compiles without a warning, and works as I expected.
8
3532
by: wespvp | last post by:
I am using PostgreSQL 7.4.1 on RedHat 7.2. The query I am executing is something like (I replaced all the return values with 'count'): db=> explain select count(*) from messages m join (select * from message_recipients r join addresses a on a.Address_Key=r.Recipient where a.Address='lra.edi@edi.cma-cgm.com') as foo on (m.Message_Key=foo.Message_Key AND (m.Message_Date >= '29-MAR-04') AND (m.Message_Date <= '31-MAR-04...
1
2728
by: Najib Abi Fadel | last post by:
Hi i have an ordered table of dates let's say: 1/1/2004 8/1/2004 15/1/2004 29/1/2004 5/2/2004 12/2/2004
0
1588
by: BillCo | last post by:
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
2
6114
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my pointers, but I'm not sure. Please help. The code: void equate(matrix *A, matrix *B) { int i, j; assert(A.row_dim == B.col_dim && A.col_dim == B.col_dim); for(i=0; i < A.row_dim; i++) for(j=0; j < A.col_dim; j++)
4
3588
by: vincibleman | last post by:
Howdy all, Working my way into SQL from Access. Think I might have the hang of the basics, but would really appreciate a sanity check. The stored procedure listed below works, but I can't help but think there is a better way to do this. Gist of what I'm doing: I need aggregate error data for each satellite in tblSatellite. -Satellite code, name, etc. -Count of number of errors over a given frame of time -The Problem Type with the...
27
2518
by: Nate Eldredge | last post by:
Consider the following pseudo-code: #include <opaque.h> struct foo { int a; opaque_t op; int b; };
0
8853
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8736
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9228
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8025
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6677
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5993
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.