Results 1 to 4 of 4
  1. #1
    Kyle02 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    16

    subquery delaying many months

    Hey,

    I have a sub query that gets the previous data. I want to re write it to get the previous data by 4 months. How would i go about doing that?
    Code:
     (SELECT MAX(T2.MonthlyDate)      
    FROM tblDates AS T2     
    WHERE T2.ProductID=tblDates.[ProductID]  
    AND T2.MonthlyDate < tblDates.MonthlyDate) As PriorDate
    How can i set it up to change the last month, to 4 months ago.. IE>

    MonthlyDate....PriorDate
    31/01/2013
    28/02/2013
    31/03/2013
    30/04/2013


    31/05/2013.....31/01/2013
    And so on....

    Thanks.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Do you want the criteria to be 4 months from the current date? Maybe:

    AND T2.MonthlyDate < DateAdd("m",-4,Date()) As PriorDate
    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.

  3. #3
    Kyle02 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    16
    That picks a date. It then goes from the MAX Date in the Selection, and minus 4 months off of it.
    right now it shows:
    MonthlyDate....PriorDate
    31/01/2013.....
    28/02/2013.....31/01/2013
    31/03/2013.....28/02/2013
    30/04/2013.....31/03/2013
    31/05/2013.....30/04/2013

    I want it to show:
    MonthlyDate....PriorDate
    31/01/2013
    28/02/2013
    31/03/2013
    30/04/2013
    31/05/2013.....31/01/2013
    30/06/2013.....28/02/2013

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    You want to subtract 4 months from the Max?

    The subquery can return only 1 value so maybe:

    (SELECT MAX(DateAdd("m",-4,T2.MonthlyDate))
    FROM tblDates AS T2
    WHERE T2.ProductID=tblDates.[ProductID]
    AND T2.MonthlyDate < tblDates.MonthlyDate) As PriorDate

    or

    (SELECT DateAdd("m",-4,Max(T2.MonthlyDate))
    FROM tblDates AS T2
    WHERE T2.ProductID=tblDates.[ProductID]
    AND T2.MonthlyDate < tblDates.MonthlyDate) As PriorDate
    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. Subquery
    By Daryl2106 in forum Access
    Replies: 20
    Last Post: 01-13-2013, 07:21 AM
  2. Subquery
    By tomclavil in forum Queries
    Replies: 3
    Last Post: 02-27-2012, 03:05 AM
  3. TOP subquery
    By helpaccess in forum Queries
    Replies: 5
    Last Post: 08-30-2011, 10:28 AM
  4. Subquery sum?
    By anemoskkk in forum Access
    Replies: 0
    Last Post: 04-29-2011, 12:36 PM
  5. Subquery
    By combine21 in forum Queries
    Replies: 2
    Last Post: 09-17-2010, 04:33 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