Results 1 to 5 of 5
  1. #1
    spqr is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    15

    Dates

    HI all,



    I have an orders table with the following fields: OrderID, CustomerID, DateOrdered and a customers table with relevant fields.

    Customers may have made a number of orders in the past, so for example customer 1 ordered in 2009 and 2010, customer 2 ordered only in 2009

    I want to create a query to find all customers that have ordered just in 2009 and NOT 2010.

    I have tried a query as follows but I get customers who have ordered in 2009 as well as 2010:

    SELECT OrderTable.[Order ID], OrderTable.[Date Ordered], OrderTable.[Customer ID]
    FROM OrderTable INNER JOIN (PlantData INNER JOIN StockOrder ON PlantData.[Plant ID] = StockOrder.[Plant ID]) ON OrderTable.[Order ID] = StockOrder.[Order ID]
    WHERE (((Year([Date Ordered]))=[please enter first year]) AND (Not (Year([Date Ordered]))=[please enter second year]));


    Thanks,

    spqr

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I remember I have answered this question last week.

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295

  4. #4
    spqr is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    15
    I can't seem to get it working. What's the logic behind your query and I can maybe figure out the sql then.

    Thanks

  5. #5
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    What's the format for the dates? Some of the smaller formats don't include the year as actual data, so the current year is always assumed.

    If you're using one of those formats, there's not really an easy way to get the data you're looking for.

    Assuming you're using a format that retains the year, try using the DateDiff() function:

    Code:
    SELECT * FROM MyTable WHERE DateDiff("yyyy", [MyDate], Date())=1
    The above Query only returns Records where the year value of [MyTable].[MyDate] and the year value of today's date is a positive 1 (meaning [MyTable].[MyDate] is 1 year BEFORE today's year).

    Note that even though you're comparing two Date/Time values, the DateDiff() function returns a Number (hence the lack of pound signs around the 1).

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

Similar Threads

  1. Calculating Dates
    By TC0126 in forum Queries
    Replies: 1
    Last Post: 02-23-2010, 08:13 PM
  2. Between dates using Iif
    By unique in forum Access
    Replies: 1
    Last Post: 01-04-2010, 07:17 AM
  3. Problems with Dates
    By oldteddybear in forum Queries
    Replies: 0
    Last Post: 08-22-2009, 07:12 AM
  4. Due dates
    By Mehbastan in forum Queries
    Replies: 5
    Last Post: 08-14-2009, 08:37 AM
  5. Exracting Dates
    By Elizabeth in forum Access
    Replies: 2
    Last Post: 04-02-2009, 11:26 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