Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2012
    Location
    Andover
    Posts
    2

    Unanswered: Studying Access Databases

    In my class were are currently learning the basics of an Access database, and I am having a problem getting it to cooperate. The question is "How many orders per year?"

    This is what I've gotten so far:

    SELECT COUNT (Orderdate)
    FROM Orders

    Now obviously that will count all of the order dates, but what I need it to do is group the orders by year and count each group. I would assume that would be:

    GROUP BY DATEPART ('YYYY')

    However, that does not work. Any suggestions?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,441
    Provided Answers: 14
    The DatePart() function expects at least 2 parameters: interval and date (both are mandatory):
    Code:
    DatePart(interval, date[,firstdayofweek, firstweekofyear]])
    Try:
    Code:
    SELECT Count(Orders.Orderdate) AS CountByYear
    FROM Orders
    GROUP BY DatePart('yyyy', Orders.Orderdate);
    Have a nice day!

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    or take advantage of some of the inbuiolt date tome functions such as year()
    group by year (orders.orderdate)
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jan 2012
    Location
    Andover
    Posts
    2
    Quote Originally Posted by Sinndho View Post
    The DatePart() function expects at least 2 parameters: interval and date (both are mandatory):
    Code:
    DatePart(interval, date[,firstdayofweek, firstweekofyear]])
    Try:
    Code:
    SELECT Count(Orders.Orderdate) AS CountByYear
    FROM Orders
    GROUP BY DatePart('yyyy', Orders.Orderdate);
    Thank you! That worked wonderfully! May I ask where you learned this stuff? I am (and my classmates) are having troubles with our teacher not telling us where to find these things.

  5. #5
    Join Date
    Mar 2009
    Posts
    5,441
    Provided Answers: 14
    Try to learn how to use the Access help features: select a keyword (e.g. "DatePart") and press the F1 key. As far as the syntax is concerned, (almost) everything you need to know is in there. Experience helps too (in my case, almost 30 years as a professional in I.T.).

    You're welcome, by the way!
    Have a nice day!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •