Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    TheSpecialist is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Georgia
    Posts
    47

    NUmber predictions

    Hello I have a database where I have dates for the past ten years and numbers along with the day the number came on. So three fields (Date, Draw, number)

    If a number came on 10/12/2014 and it was 555. I want to be able to see all the numbers that came two days before and two days after this date. What do I need to put in my criteria for my query to see this information



    Thank you in advance

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Date is a reserved word in Access.


    General criteria would be along this pattern
    Code:
    ..... Where  SearchDate is Between YourDate -2 and YourDate +2

  3. #3
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    I'm using dd/mm/yyyy format.

    When you say 'two days before and two days after', do you mean 08/12/2014 through 12/12/2014 or do you mean the last two days before 10/12/2014 for which there is data and the next two after 10/12/2014 for which there is data?

    If the former (i.e. dates are contiguous) this should do it -
    SELECT bytNumber FROM tblMyTable WHERE Not dtmDate = CDate("10/12/14") And dtmDate Between CDate("10/12/14") - 2 And CDate("10/12/14") + 2

    Otherwise, it's a wee bit more complicated -
    SELECT bytNumber
    FROM tblMyTable
    WHERE dtmDate IN (SELECT DISTINCT TOP 2 dtmDate FROM tblMyTable WHERE dtmDate<CDate("10/12/2014") ORDER BY dtmDate DESC)
    UNION ALL SELECT bytNumber
    FROM tblMyTable
    WHERE dtmDate IN (SELECT DISTINCT TOP 2 dtmDate FROM tblMyTable WHERE dtmDate>CDate("10/12/2014") ORDER BY dtmDate)

    I hope this helps.

  4. #4
    TheSpecialist is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Georgia
    Posts
    47
    Yes, I am using the 10/12/2012 so I want to see for instance 10/10/2012 to 10/14/2012 I want to see the numbers that came before 10/12/2014 and 2 days after 10/12/2012. How can I put that in my criteria so it will pull all the numbers on these days before 10/12/2012 and (2 days) before that date and 2 days after that date.

  5. #5
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Oh, I see ... you're in the USA looking for dates in October ... so use these -

    SELECT bytNumber FROM tblMyTable WHERE Not dtmDate = CDate("12/10/14") And dtmDate Between CDate("12/10/14") - 2 And CDate("12/10/14") + 2

    OR

    SELECT bytNumber
    FROM tblMyTable
    WHERE dtmDate IN (SELECT DISTINCT TOP 2 dtmDate FROM tblMyTable WHERE dtmDate < CDate("12/10/2014") ORDER BY dtmDate DESC)
    UNION ALL SELECT bytNumber
    FROM tblMyTable
    WHERE dtmDate IN (SELECT DISTINCT TOP 2 dtmDate FROM tblMyTable WHERE dtmDate > CDate("12/10/2014") ORDER BY dtmDate)

  6. #6
    TheSpecialist is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Georgia
    Posts
    47
    Is it anyway I can put it in the criteria section of the query design view

  7. #7
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    If I understand your question ... start a new query, select SQL View, paste my suggested query to replace the highlighted 'SELECT;', select Design View.

    This will only work with the simple (first) suggestion.

    You'll need this table (but with your October dates) -
    Click image for larger version. 

Name:	aaa.jpg 
Views:	14 
Size:	28.2 KB 
ID:	21247

  8. #8
    TheSpecialist is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Georgia
    Posts
    47
    Click image for larger version. 

Name:	data.gif 
Views:	14 
Size:	51.7 KB 
ID:	21246

    this is how it looks and I wanted to be able to see the dates 2 days before this number came and two days after this number came. How will I put it in my criteria section of the query

  9. #9
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    You should be able to work out your problem from here.

  10. #10
    TheSpecialist is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Georgia
    Posts
    47
    thank you so much

  11. #11
    TheSpecialist is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Georgia
    Posts
    47
    Is it away that I can use any number I want in my database and apply the two days before and two days after regardless. For instance, if I want to use 123 and I want to be able to see all the times this number occurred and then I want to see all the numbers that came two days before the number and two days after that number. Is it a query for that as well

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Yes.
    You would have query A that finds all Dates where your searchNumber occurs.
    Then, query B would take each Date in queryA and do the search for 2 days before and after each Date.

    For clarity and simplicity, you might want to have queryA store those Dates in a Table say TableWithDates.
    Then use the Dates in TableWithDates in your earlier query.

    Can you tell us what you plan to use this information for?

  13. #13
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,844
    looks like exactly the same question as here

    https://www.accessforums.net/queries...tml#post283343

  14. #14
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    @Ajax

    I agree seems eerily similar. Grammar seems a little different ??Could it be a class project???

  15. #15
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,844
    Probably - first thread for both OP's.

    Looks like my boy is slightly ahead of the game - at least he referred to the dateadd function

    Will continue to watch their posts with interest....

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 06-21-2015, 12:33 AM
  2. Replies: 5
    Last Post: 11-30-2014, 12:46 PM
  3. Replies: 6
    Last Post: 01-24-2013, 10:02 PM
  4. Replies: 0
    Last Post: 10-22-2012, 02:45 PM
  5. Replies: 6
    Last Post: 07-25-2011, 01:54 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