CFF KB - Carrz-Fox-Fire Promotions Knowledge Base

CFF KB is all about 1 thing: The Sharing of Knowledge and the Power we gain from it.
  • Breadrumbs:
  • Microsoft JET Database Engine (0x80040E21) part of an aggregate function

  • CFF Knowledge Base - Share With Facebook CFF Knowledge Base - Share on Twitter CFF Knowledge Base - Share on Reddit CFF Knowledge Base - Share on Digg It CFF Knowledge Base - Share on Stumble Upon It CFF Knowledge Base - Share on Delicious
    Share With Friends (Updated 6-8-2010)
  • Article ID:
    70
  • Date Created
    Tuesday, December 14, 2010
  • This Article Has been Viewed
    2313 times
  • Short Desc
    When you build your QUERY with a COUNT you will have to add in all columns into a GROUP BY within your statement query.
  • Details
    Builing a Query Statement for your ASP page within Access (or) SQL Server with a COUNT, you will have to add in all columns into a GROUP BY within the statement, if not you will get the following error.

     
    Microsoft JET Database Engine (0x80040E21)
    You tried to execute a query that does not include the specified expression 'username' as part of an aggregate function.
    /header.asp, line 39
  • Recreate Issue
    To recreate this issue.

    <%
    sql.commandtext="select count(column1)as ctCol, col2, col3, col4 from table1"
    %>
  • Resolve Issue
    To use the GROUP BY within your Statement Query, do the following:

    <%
    sql.commandtext="select count(column1)as ctCol, col2, col3, col4 from table1 Group By col2, col3, col4"
    %>


    As you can see, we have added the Group By to our statement with the col2, col3, col4 added in so that we can use them in our page.