Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2008
    Posts
    15

    Unanswered: Multiple records from last 2 dates

    Hi all, I am sure this has been covered somewhere but google and site search didn't have my reply so forgive me. I am trying to run a query that will return all of the records from the previous 2 dates. These dates are not regular intervals nor are they consistent so the dates might be yesterday and today or they might be 8 months ago and 2 months ago. Also for each date there will be multiple records. Hope that makes sense.

    Thanks
    Newbie trying to find his way through Access...

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    If I understand you correctly, the SQL Statement for the Query would be something like

    Code:
    SELECT TOP 2 ActualTableName.DateField, ActualTableName.NName, ActualTableName.DateField
    FROM ActualTableName
    ORDER BY ActualTableName.DateField DESC;


    replacing ActualTableName, DateField, NName with the actual names of these Table/Fields.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Im not sure thats how I read the post, but Im not claiming better knowledge. I read it as return all rows that fall on two specific dates

    I put it all down to the 'where' clause

    WHERE mydatefield = #2013-08-20# or mydatefield = #2012-12-31#

    the # delimits the beginning and end of the date literal
    the date value shoudl be expressed as iso date format

    you may be able to use the in construct
    WHERE mydatefield in (#2013-08-20#, #2012-12-31#)
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by healdem View Post

    ...I read it as return all rows that fall on two specific dates...
    Quote Originally Posted by BDevil15 View Post

    ...These dates are not regular intervals nor are they consistent so the dates might be yesterday and today or they might be 8 months ago and 2 months ago...
    Maybe I'm missing something, too, but the dates apparently are the last two dates in the Table, whatever they are, not two specific dates.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Aug 2008
    Posts
    15
    Here is a link to the db.

    http://www.mediafire.com/download/a1...atabase1.accdb

    In this example I would like the query to return all of the grades from 8/20/2013 as well as those from 4/16/2013.

    But if I added new grades tomorrow then I would only want those from 8/20/2013 and 8/21/2013.

    Hope that makes more sense. Thanks for the help.
    Newbie trying to find his way through Access...

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by Missinglinq View Post
    Maybe I'm missing something, too, but the dates apparently are the last two dates in the Table, whatever they are, not two specific dates.

    Linq ;0)>
    ...good point, well made

    not to sure you can get multiple rows for the last to days in one hit, but Im open to persuasion.

    right now Id do this as a two part process
    first find the TOP two dates, then use those dates as a feed stock into a where clause and pull all orws on those dates.
    you could implement this as a stored procedure, assumign you are using Access 2010 or later
    if not then you coudl fake a stored procedure using a function
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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