+ Reply to Thread
Results 1 to 6 of 6

Help with query

  1. #1
    Registered User
    Join Date
    01-08-2009
    Location
    Colorado
    MS-Off Ver
    Excel 2007, 2010 PC, 2011 Mac
    Posts
    41

    Help with query

    I have very little knowledge of access, but knowledge of how databases in general function. I inherited this database and did not create it.

    I am using Access 2007.

    I have a report that is driven by a query. It is returning records that the sum is 0. I would like to not display the records where the sum is 0.
    I tried modifying the query in design view but I can't seem to get it to work. So I switched to the SQL view and have been trying to get that working. I can get access to accept the SQL but when I run it it asks me for the value that I put >0 in the query.

    Here is the SQL Query
    Please Login or Register  to view this content.
    With the code above it prompts me for the value of SumOfAdjustment. I am unsure of what I am doing wrong.

    In the design view I was able to get access to add a HAVING line in SQL. This did not ask for the value but it did not generate the correct results either.

    The end result would be showing just the records where SumOfAdjustment >0.



    Thanks

    Brian
    Last edited by extrapulp; 01-18-2010 at 10:11 AM. Reason: Reworded added more info

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Help with query

    In the query SQL, you can't reference field aliases in the FROM, WHERE, GROUP BY, HAVING, or ORDER BY sections.

    Try this:

    Please Login or Register  to view this content.

    Does that help?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    01-08-2009
    Location
    Colorado
    MS-Off Ver
    Excel 2007, 2010 PC, 2011 Mac
    Posts
    41

    Re: Help with query

    Ron,

    Access now throws an error dialog with this text in it "Cannot have aggregate function in WHERE clause (Sum(LotAdjustment.Adjustment)>0)."

    Thanks for your quick reply!

    Brian

  4. #4
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Help with query

    How about this:

    Please Login or Register  to view this content.
    Cheers,
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Help with query

    Quote Originally Posted by extrapulp View Post
    Ron,

    Access now throws an error dialog with this text in it "Cannot have aggregate function in WHERE clause (Sum(LotAdjustment.Adjustment)>0)."

    Thanks for your quick reply!

    Brian
    Try moving the criteria into a HAVING clause:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-08-2009
    Location
    Colorado
    MS-Off Ver
    Excel 2007, 2010 PC, 2011 Mac
    Posts
    41

    Re: Help with query

    Ron,

    That works great!

    Thank you!

    Brian

+ 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