+ Reply to Thread
Results 1 to 3 of 3

Aggregate function

  1. #1
    Registered User
    Join Date
    08-25-2004
    Posts
    15

    Aggregate function

    Table (Field1, Field2)

    a = "SELECT SUM(T.Field2) AS F FROM Table AS T WHERE T.field1=1"
    Set rs = db.OpenRecordset(a)
    It works.

    but
    a = "SELECT T.field1, SUM(T.Field2) AS F FROM Table AS T WHERE T.field1=1"
    Set rs = db.OpenRecordset(a)
    It doesn't work.

    Run-time error '3122': You tried to execute a query that does not include the specified expresion 'field1' as part of an aggregate function.)

  2. #2
    Martin Fishlock
    Guest

    RE: Aggregate function

    Try using group by as in:

    a = "SELECT T.field1, SUM(T.Field2) AS F FROM Table AS T WHERE
    T.field1=1 group by T.Field1"
    ....
    --
    HTHs Martin


    "stefantem" wrote:

    >
    > Table (Field1, Field2)
    >
    > a = "SELECT SUM(T.Field2) AS F FROM Table AS T WHERE T.field1=1"
    > Set rs = db.OpenRecordset(a)
    > It works.
    >
    > but
    > a = "SELECT T.field1, SUM(T.Field2) AS F FROM Table AS T WHERE
    > T.field1=1"
    > Set rs = db.OpenRecordset(a)
    > It doesn't work.
    >
    > Run-time error '3122': You tried to execute a query that does not
    > include the specified expresion 'field1' as part of an aggregate
    > function.)
    >
    >
    > --
    > stefantem
    > ------------------------------------------------------------------------
    > stefantem's Profile: http://www.excelforum.com/member.php...o&userid=13594
    > View this thread: http://www.excelforum.com/showthread...hreadid=502805
    >
    >


  3. #3
    Registered User
    Join Date
    08-25-2004
    Posts
    15
    It works. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1