Results 1 to 6 of 6
  1. #1
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138

    SQL Troubles

    I am trying to create a query to count the records between for the past 3 months. This is what I have so far:

    "SELECT Format(TBDate,'mmmm') as Month, COUNT (TBDate) as cnt INTO ChartTable FROM Turnbacks WHERE TBDate BETWEEN DateAdd(""m"", -3, Date()) AND Date();"

    I am gettting:

    Syntax error (missing operator) in query expression 'TBDate BETWEEN DateAdd(""mmmm"", -3, Date()) AND Date()'.



    I am just not sure what I am missing. This is the first time I have tried building an SQL statement this "complex".

  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,641
    Try replacing all the quotes around the m with single quotes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138
    Tried the suggested change, and now I am getting:

    You tried to execute a query that does not include the specified expression 'Format(TBDate,'mmmm')' as part of the aggregate function.

    I am not even sure what this means. What I am trying to do is query all of the records that are for the past 3 months into a table and count them by month. I need the month text in one column and the count in the other. maybe I am going about this all wrong, Suggestions?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Normally a totals query requires that any field not aggregated (sum, count, etc) must be in a GROUP BY clause. Try adding this to the end:

    GROUP BY Format(TBDate,'mmmm')
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138
    Thank you so much. That was exactly what I needed.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    No problem.
    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. Subquery Troubles
    By glennib in forum Queries
    Replies: 1
    Last Post: 07-11-2013, 01:08 PM
  2. Subreport Keep Together troubles
    By chris.williams in forum Reports
    Replies: 1
    Last Post: 09-07-2012, 12:29 PM
  3. Query troubles.
    By SteveSummers in forum Access
    Replies: 1
    Last Post: 10-26-2011, 07:48 PM
  4. Running Sum Troubles
    By royalrochelle in forum Reports
    Replies: 2
    Last Post: 09-10-2011, 05:13 AM
  5. Query troubles
    By dmullins in forum Reports
    Replies: 0
    Last Post: 10-20-2009, 02:17 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