Results 1 to 5 of 5
  1. #1
    silverxx12 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    18

    Unhappy Query problem

    Hi

    I have three criteria in my table

    name
    shipdate
    qty (£ amount)

    using the following code i am able to filter by period eg jan - dec to see in that period the name and dates, quantites bought.

    SELECT [Table].Name, [Table].nShipDate, Sum([Table].Qty) AS SumOfQty
    FROM [Table]
    GROUP BY [Table].Name, [Table].nShipDate


    HAVING ((([Table].nShipDate) Between #1/1/2012# And #12/31/2012#));


    However i am faced with the following issues:

    I need firstly to sum all the qty's per name - ie i dont want to see two entries on different dates for the same name with two amounts.

    And secondly I only want to see the last date in the sequence of the nshipdate relating to each name for eg: say Jim has the following data

    Name nshipdate qty
    Jim 12/1/12 $200
    Jim 18/1/12 $800

    I would like to see the following

    Jim 18/1/12 $1000

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Try

    SELECT [Table].Name, Max([Table].nShipDate) As MaxDate, Sum([Table].Qty) AS SumOfQty
    FROM [Table]
    WHERE [Table].nShipDate Between #1/1/2012# And #12/31/2012#
    GROUP BY [Table].Name

    A WHERE clause is more appropriate than a HAVING clause in this situation (Access often guesses wrong).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by pbaldy View Post
    Try

    SELECT [Table].Name, Max([Table].nShipDate) As MaxDate, Sum([Table].Qty) AS SumOfQty
    FROM [Table]
    WHERE [Table].nShipDate Between #1/1/2012# And #12/31/2012#
    GROUP BY [Table].Name

    A WHERE clause is more appropriate than a HAVING clause in this situation (Access often guesses wrong).
    Also, note that "Name" is a reserved word in Access - it is a property of many objects - and shouldn't be used for object names. Plus, it is not very descriptive ... "Name" of what?? Your dog, the city,...

    You could try putting brackets around it :

    Code:
    SELECT [Table].[Name], Max([Table].nShipDate) As MaxDate,

  4. #4
    silverxx12 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    18
    GENIUS!!!!!!!

    this was driving me mad for a while - ty so much

    i orginally placed the date criteria under the sort by max and this was messing me up then went back to basics

    really appreciate it :-)

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query problem
    By lamkee in forum Queries
    Replies: 13
    Last Post: 12-12-2010, 10:30 PM
  2. Query problem
    By puppychew in forum Access
    Replies: 20
    Last Post: 02-01-2010, 09:43 AM
  3. Query Problem
    By rblundell in forum Queries
    Replies: 2
    Last Post: 11-26-2009, 08:29 PM
  4. query problem i have a problem wi
    By maxx3 in forum Queries
    Replies: 0
    Last Post: 06-29-2009, 02:29 AM
  5. Problem in Query
    By Bruno Trindade in forum Queries
    Replies: 4
    Last Post: 03-28-2009, 04:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums