Results 1 to 2 of 2
  1. #1
    rbennion is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Jun 2017
    Posts
    17

    Why does Access make me format my dates when grouping by month with an aggregate

    Title pretty much says it all. I am confused why i can't simply use the following code for the year 2016:



    SELECT Month(Discharge_Date), Sum(#_OCR_Sessions)
    FROM [General]
    WHERE YEAR(Discharge_Date) = '2016'
    GROUP BY Month(Discharge_Date);

    I got the query to run, (honestly in a better way) by using the following:

    SELECT Format([Discharge_Date],"yyyy"", ""mm") AS [Month], Sum([#_OCR_Sessions]) AS [SumOfSessions]
    FROM [General]
    GROUP BY Format([Discharge_Date],"yyyy"", ""mm");


    This shows all years and the months of those years, which is nice.

    My question is purely out of curiosity, why does it make me format when i'm using an aggregate?

    Thanks!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Month is a reserved word. Should not use reserved words as names. Also advise no spaces or punctuation/special characters (underscore only exception).


    If you prefer:

    SELECT Year([Discharge_Date]) AS Yr, Month([Discharge_Date]) AS Mo, Sum([#_OCR_Sessions]) AS [SumOfSessions]
    FROM [General]
    GROUP BY Year([Discharge_Date]), Month([Discharge_Date]);
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Grouping Data by dates
    By chr1stoper1 in forum Access
    Replies: 5
    Last Post: 01-17-2017, 02:26 PM
  2. Grouping and dates
    By loonytoons in forum Queries
    Replies: 4
    Last Post: 02-24-2015, 10:28 AM
  3. Replies: 2
    Last Post: 05-19-2013, 06:03 AM
  4. Grouping by Month in Report
    By ccordner in forum Reports
    Replies: 2
    Last Post: 12-20-2011, 09:05 AM
  5. Replies: 4
    Last Post: 04-09-2011, 10:39 AM

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