+ Reply to Thread
Results 1 to 9 of 9

aggregate functions: problem with SELECT SUM()

  1. #1
    Registered User
    Join Date
    06-09-2006
    Posts
    62

    aggregate functions: problem with SELECT SUM()

    Hi all,
    I am in dire need of help here.

    my code below does not return the expected value.
    mind that code works if I replace the sql statement with something such as:
    SELECT c_name FROM c_production WHERE id=513

    I did some reading and I suspect the following
    1. not sure if objDB.Execute is the right syntax (some wrote OpenRecordset)
    2. I'm not sure the loop is necessary because the sql suppose to return one value.

    THANKS FOR ANY POINTERS!!!



    Please Login or Register  to view this content.
    Last edited by mudraker; 05-11-2007 at 02:35 AM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    You might already have tried this. Just in case you haven't...


    Try running your SQL statement against the DB directly - does it work then?
    Martin

  3. #3
    Registered User
    Join Date
    06-09-2006
    Posts
    62
    hi there,
    yes in my db, this query returns a value and it's working fine.

  4. #4
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    Try this WHERE at the end of your SELECT :
    Please Login or Register  to view this content.
    Just keep it simple !


    http://www.excelguide.eu
    In English as well as in Dutch

  5. #5
    Registered User
    Join Date
    06-09-2006
    Posts
    62
    mmm..still not.
    even with your suggested query it doesn't work


  6. #6
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    And this way : ?

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-09-2006
    Posts
    62
    thank you for trying. I didn't test your code because it is obvious it will not work. the problem is not in the id section! it's in the sum section.

    I don't need to test that because I'm trying to get this

    SELECT sum(c_amount) FROM c_production WHERE id=513

    id= 513

    so my conclusion is somewhere around the sum(c_amount) which is wrong.

    once again, thanks for trying.

  8. #8
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-09-2006
    Posts
    62
    why do you think this would solve it? the 'AS' is for developers...it facilitates their queries, it has nothing to do with the query's result.

    SELECT sum(c_amount) AS SumAmount FROM

+ 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