PC Review


Reply
Thread Tools Rate Thread

Aggregate function error

 
 
LAS
Guest
Posts: n/a
 
      24th Aug 2010
I get this error
"You tried to execute a query that does not include the specified expression 'ProbBehaveCat1_Desc' as part of an aggregate function."

when I execute query 2. Query 1 works fine. Before Access blew up on me, a function that produced Query 2 also worked fine. HELP!!! Can anyone figure out what might be wrong?

QUERY 1 - typed directly into the query builder
SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1, tblStudentTracking.ProbBehaveCat1_Desc
FROM tblStudentTracking, tblStudents
WHERE tblStudents.Student_ID=tblStudentTracking.Student_ID
And tblStudentTracking.Student_ID=374
And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
GROUP BY tblStudentTracking.ProbBehaveCat1_Desc
ORDER BY tblStudentTracking.ProbBehaveCat1_Desc;


QUERY 2 - Cut and pasted from Immediate View in a function that builds this query string (end of line inserted by me)
SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1, tblStudentTracking.ProbBehaveCat1_Desc
FROM tblStudentTracking, tblStudents
WHERE tblStudents.Student_ID=tblStudentTracking.Student_ID
and tblStudentTracking.Student_ID = 374
And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
GROUP BY tblStudentTracking.ProbBehaveCat1__Desc
ORDER BY tblStudentTracking.ProbBehaveCat1__Desc;
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      24th Aug 2010
On Tue, 24 Aug 2010 18:21:28 -0400, "LAS" <(E-Mail Removed)> wrote:

>I get this error
>"You tried to execute a query that does not include the specified expression 'ProbBehaveCat1_Desc' as part of an aggregate function."
>
>when I execute query 2. Query 1 works fine. Before Access blew up on me, a function that produced Query 2 also worked fine. HELP!!! Can anyone figure out what might be wrong?
>
>QUERY 1 - typed directly into the query builder
>SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1, tblStudentTracking.ProbBehaveCat1_Desc
>FROM tblStudentTracking, tblStudents
>WHERE tblStudents.Student_ID=tblStudentTracking.Student_ID
>And tblStudentTracking.Student_ID=374
>And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
>GROUP BY tblStudentTracking.ProbBehaveCat1_Desc
>ORDER BY tblStudentTracking.ProbBehaveCat1_Desc;
>
>
>QUERY 2 - Cut and pasted from Immediate View in a function that builds this query string (end of line inserted by me)
>SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1, tblStudentTracking.ProbBehaveCat1_Desc
>FROM tblStudentTracking, tblStudents
>WHERE tblStudents.Student_ID=tblStudentTracking.Student_ID
>and tblStudentTracking.Student_ID = 374
>And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
>GROUP BY tblStudentTracking.ProbBehaveCat1__Desc
>ORDER BY tblStudentTracking.ProbBehaveCat1__Desc;


Are you intending Desc to mean "sort in descending order"? What in fact is the
field name in your table... ProbBehaveCat1 or something else?

If my guess is correct try

SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1,
tblStudentTracking.ProbBehaveCat1
FROM tblStudentTracking, tblStudents
WHERE tblStudents.Student_ID=tblStudentTracking.Student_ID
And tblStudentTracking.Student_ID=374
And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
GROUP BY tblStudentTracking.ProbBehaveCat1
ORDER BY tblStudentTracking.ProbBehaveCat1 Desc;
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
LAS
Guest
Posts: n/a
 
      24th Aug 2010
Desc is part of the field name.

The field name, as used in both queries is ProbBehaveCat1_Desc

It works fine in one.

Not in the other.

Can you see a difference that would cause one to fail?

"John W. Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message
news:(E-Mail Removed)...
> On Tue, 24 Aug 2010 18:21:28 -0400, "LAS" <(E-Mail Removed)> wrote:
>
>>I get this error
>>"You tried to execute a query that does not include the specified
>>expression 'ProbBehaveCat1_Desc' as part of an aggregate function."
>>
>>when I execute query 2. Query 1 works fine. Before Access blew up on me,
>>a function that produced Query 2 also worked fine. HELP!!! Can anyone
>>figure out what might be wrong?
>>
>>QUERY 1 - typed directly into the query builder
>>SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1,
>>tblStudentTracking.ProbBehaveCat1_Desc
>>FROM tblStudentTracking, tblStudents
>>WHERE tblStudents.Student_ID=tblStudentTracking.Student_ID
>>And tblStudentTracking.Student_ID=374
>>And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
>>GROUP BY tblStudentTracking.ProbBehaveCat1_Desc
>>ORDER BY tblStudentTracking.ProbBehaveCat1_Desc;
>>
>>
>>QUERY 2 - Cut and pasted from Immediate View in a function that builds
>>this query string (end of line inserted by me)
>>SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1,
>>tblStudentTracking.ProbBehaveCat1_Desc
>>FROM tblStudentTracking, tblStudents
>>WHERE tblStudents.Student_ID=tblStudentTracking.Student_ID
>>and tblStudentTracking.Student_ID = 374
>>And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
>>GROUP BY tblStudentTracking.ProbBehaveCat1__Desc
>>ORDER BY tblStudentTracking.ProbBehaveCat1__Desc;

>
> Are you intending Desc to mean "sort in descending order"? What in fact is
> the
> field name in your table... ProbBehaveCat1 or something else?
>
> If my guess is correct try
>
> SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1,
> tblStudentTracking.ProbBehaveCat1
> FROM tblStudentTracking, tblStudents
> WHERE tblStudents.Student_ID=tblStudentTracking.Student_ID
> And tblStudentTracking.Student_ID=374
> And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
> GROUP BY tblStudentTracking.ProbBehaveCat1
> ORDER BY tblStudentTracking.ProbBehaveCat1 Desc;
> --
>
> John W. Vinson [MVP]
> Microsoft's replacements for these newsgroups:
> http://social.msdn.microsoft.com/For...-US/accessdev/
> http://social.answers.microsoft.com/.../en-US/addbuz/
> and see also http://www.utteraccess.com



 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      25th Aug 2010
It would help if you posted the function that creates the string.

You said you inserted the line breaks in query 2. That changes the query and
hides any occurrence of missing spaces between elements of the query string.

If you paste the code generated string directly into a new query (in SQL
view), does it run or does it error? If you paste the code as modified (with
the line breaks) does it run or does it error?

Also, I wonder why your query is using the NZ function at all in this line.
And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
when the following will return the exact same records
And tblStudentTracking.ProbBehaveCat1_Code='xOther'

Also, why are you not using a join in the query. The following query should
be much more efficient.

SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1
, tblStudentTracking.ProbBehaveCat1_Desc
FROM tblStudentTracking INNER JOIN tblStudents
ON tblStudentTracking.Student_ID =tblStudents.Student_ID
WHERE tblStudentTracking.Student_ID=374
And tblStudentTracking.ProbBehaveCat1_Code ='xOther'
GROUP BY tblStudentTracking.ProbBehaveCat1_Desc
ORDER BY tblStudentTracking.ProbBehaveCat1_Desc;

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

LAS wrote:
> I get this error
> "You tried to execute a query that does not include the specified expression 'ProbBehaveCat1_Desc' as part of an aggregate function."
>
> when I execute query 2. Query 1 works fine. Before Access blew up on me, a function that produced Query 2 also worked fine. HELP!!! Can anyone figure out what might be wrong?
>
> QUERY 1 - typed directly into the query builder
> SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1, tblStudentTracking.ProbBehaveCat1_Desc
> FROM tblStudentTracking, tblStudents
> WHERE tblStudents.Student_ID=tblStudentTracking.Student_ID
> And tblStudentTracking.Student_ID=374
> And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
> GROUP BY tblStudentTracking.ProbBehaveCat1_Desc
> ORDER BY tblStudentTracking.ProbBehaveCat1_Desc;
>
>
> QUERY 2 - Cut and pasted from Immediate View in a function that builds this query string (end of line inserted by me)
> SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS Expr1, tblStudentTracking.ProbBehaveCat1_Desc
> FROM tblStudentTracking, tblStudents
> WHERE tblStudents.Student_ID=tblStudentTracking.Student_ID
> and tblStudentTracking.Student_ID = 374
> And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
> GROUP BY tblStudentTracking.ProbBehaveCat1__Desc
> ORDER BY tblStudentTracking.ProbBehaveCat1__Desc;

 
Reply With Quote
 
David W. Fenton
Guest
Posts: n/a
 
      25th Aug 2010
John Spencer <(E-Mail Removed)> wrote in
news:i5361k$u6s$(E-Mail Removed):

> Also, I wonder why your query is using the NZ function at all in
> this line.
> And nz(tblStudentTracking.ProbBehaveCat1_Code,'')='xOther'
> when the following will return the exact same records
> And tblStudentTracking.ProbBehaveCat1_Code='xOther'


I had to think through this one.

If you do As John suggested, all the Nulls will be excluded.

If you leave it alone, rows with Nulls will be tested against a ZLS,
and they will be excluded because ""<>"xOther".

So, yes, John is right -- there is no utility in the Nz() test, just
a performance drain.

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/
 
Reply With Quote
 
David W. Fenton
Guest
Posts: n/a
 
      25th Aug 2010
John Spencer <(E-Mail Removed)> wrote in
news:i5361k$u6s$(E-Mail Removed):

> Also, why are you not using a join in the query. The following
> query should be much more efficient.
>
> SELECT Sum(fncElapsedTime(Incident_Time,Incident_Return_Time)) AS
> Expr1 , tblStudentTracking.ProbBehaveCat1_Desc
> FROM tblStudentTracking INNER JOIN tblStudents
> ON tblStudentTracking.Student_ID =tblStudents.Student_ID
> WHERE tblStudentTracking.Student_ID=374
> And tblStudentTracking.ProbBehaveCat1_Code ='xOther'
> GROUP BY tblStudentTracking.ProbBehaveCat1_Desc
> ORDER BY tblStudentTracking.ProbBehaveCat1_Desc;


Not necessarily -- Jet/ACE generally optimizes an explicit JOIN
exactly the same as the equivalent implicit JOIN (i.e., a "join"
done in the WHERE clause). While I see no reason not to use the JOIN
(since it makes more sense), I don't think it will result in a
performance improvement (though I can't recall that I've ever run
SHOWPLAN on implicit joins in aggregate queries).

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Aggregate function error Yam84 Microsoft Access Queries 2 29th May 2008 04:47 PM
aggregate function error CEV Microsoft Access Queries 7 9th Jan 2008 08:52 PM
ERROR: aggregate function? =?Utf-8?B?bXVzb3NkZXY=?= Microsoft Access Queries 4 20th Feb 2007 10:38 AM
aggregate function error TommyT Microsoft Access Reports 2 15th Jan 2007 04:24 AM
aggregate function error =?Utf-8?B?dG9wZTEy?= Microsoft Access Queries 1 15th Nov 2005 03:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:55 AM.