Results 1 to 2 of 2
  1. #1
    ubnkp is offline Novice
    Windows XP Access 2000
    Join Date
    Apr 2010
    Posts
    2

    Return sum column based on another column Where statement date minus x months

    This is my attempt at writing an Access SQL statement but it's not quite working for me and I am not sure how to ask the query correctly to get my intended result.

    I need the statement to select from my table the column named DEPT and also return the sum of the headcount value from rows which meet the criteria "Entitlement Since" (name of a column within my table which is date based) is greater than 30 months ago from todays date.

    Thanks, Amber.

    SELECT Table.[Dept], SUM(Tablel.Headcount) AS CurrentMonth
    FROM Table
    WHERE Tablel.[Entitlement Since]< DateAdd("m",-29,Date());

    I need the statement to select from my table the column named DEPT and also return the sum of the headcount value from rows which meet the criteria "Entitlement Since" (which is a date) is greater than 30 months ago from todays date.
    Here's an example of the Table (1) and the required return Query results (2)

    (1)
    DEPT Entitlement Since HeadCount
    D1 1/09/2007 1
    D1 1/09/2007 1
    D2 1/09/2007 1
    D2 1/01/2010 1
    D2 1/01/2010 1

    (2) There are 3 rows which fit the criteria "Entitlement Since" date value is more than 30 months ago from the current month. These rows are to be selected and sumed according to the Dept - D1 and D2.
    DEPT Now
    D1 2


    D2 1
    Last edited by ubnkp; 04-15-2010 at 02:12 AM.

  2. #2
    ubnkp is offline Novice
    Windows XP Access 2000
    Join Date
    Apr 2010
    Posts
    2
    I have solved my own question.

    The answer that I worked out was:

    SELECT [Table].[Dept], sum(nz([Table].[HeadCount],0)) AS CurrentMonth
    FROM Table
    WHERE [Table].[Entitlement Since] < DateAdd("m",-29,Date())
    GROUP BY [Table].[Dept]
    ORDER BY [Table].[Dept];

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

Similar Threads

  1. Query criteria, add 5 months to date
    By thart21 in forum Queries
    Replies: 1
    Last Post: 03-29-2010, 05:09 PM
  2. Total all months in query or report
    By Brian62 in forum Queries
    Replies: 2
    Last Post: 10-23-2009, 08:41 AM
  3. How to show all months
    By Brian62 in forum Queries
    Replies: 4
    Last Post: 10-20-2009, 08:55 AM
  4. A months query
    By Peljo in forum Access
    Replies: 1
    Last Post: 02-18-2008, 09:07 AM
  5. Replies: 1
    Last Post: 11-11-2006, 08:00 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