Results 1 to 5 of 5
  1. #1
    quentinfox is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    2

    Date Query help needed (comparison help)

    I need to write a query that will allow me to return records where a date in the record plus a number of days (in the record) is greater than a date that I enter. For example, if I have a termination date of 7/1/13 with a 90 day noneligible day count and my date is 8/1/13, I would expect that record to return because 7/1+90days>8/1. If my date was 11/15/13, I would not want that record since 7/1+90 days<11/15.

    Hope that all makes sense.

    I've tried a couple of things...

    DateAdd("d",[Fee Billing Cur Mo (Raw Data)]![noneligible_day_cnt],[Fee Billing Cur Mo (Raw Data)]![TerminationDate])>[my date]... returns all records and gives a value of -1.



    [Fee Billing Cur Mo (Raw Data)]![TerminationDate]+[Fee Billing Cur Mo (Raw Data)]![noneligible_day_cnt]>[my date]... also returns -1.

    If I change the item immediately above to "Expression" in the totla field and move the >[my date] to the criteria field, it reduces my record count substantially, but they still aren't right. I still have records returned that are less than my target date.


    Thanks in advance to the forum for help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,640
    DateDiff expects the first date argument to be the earlier date value. Day is default unit when calculating date values. Try:

    SELECT * FROM tablename WHERE datefield + somevalue > somedate;

    SELECT * FROM [Fee Billing Cur Mo (Raw Data)] WHERE TerminationDate + noneligible_day_cnt >#[my date]#;
    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
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    First - you actually have parenthesis in a table name? Gakk! You like to make your life difficult.
    Second -
    Code:
    SELECT TF.MyField1, TF.MyField2
    FROM [Fee Billing Cur Mo (Raw Data)] AS TF
    WHERE (dateadd("D",NZ(TF.[noneligible_day_cnt],NZ(TF.[TerminationDate])) > [MyDate];
    should work, as long as [MyDate] is available to the SQL.

    I've put NZ around the date fields to trap any null records. In general, I would do the same around the fields in June's second example, and use DateAdd rather than the + operator. But, I'm paranoid hat way.

    What, precisely, do you mean when you say it returns -1? How are you doing it?

  4. #4
    quentinfox is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    2

    Making my own life difficult...

    That's too funny. The parenthesis in my table name had never crossed my mind. I'll probably get rid of them.

    I'll try your solutions this morning and report back.

    Thanks much to you both!

    Q




    Quote Originally Posted by Dal Jeanis View Post
    First - you actually have parenthesis in a table name? Gakk! You like to make your life difficult.
    Second -
    Code:
    SELECT TF.MyField1, TF.MyField2
    FROM [Fee Billing Cur Mo (Raw Data)] AS TF
    WHERE (dateadd("D",NZ(TF.[noneligible_day_cnt],NZ(TF.[TerminationDate])) > [MyDate];
    should work, as long as [MyDate] is available to the SQL.

    I've put NZ around the date fields to trap any null records. In general, I would do the same around the fields in June's second example, and use DateAdd rather than the + operator. But, I'm paranoid hat way.

    What, precisely, do you mean when you say it returns -1? How are you doing it?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,640
    As Dal pointed out, parens and other special characters and punctuation (underscore is exception) should be avoided, as well as spaces, in names. Also, no reserved words as names.
    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. Date comparison syntax in query criteria
    By SyntaxSocialist in forum Queries
    Replies: 3
    Last Post: 04-09-2013, 08:39 AM
  2. Replies: 3
    Last Post: 11-20-2012, 09:52 AM
  3. RC Notation and Date Comparison
    By mkc80 in forum Access
    Replies: 2
    Last Post: 10-10-2012, 06:22 PM
  4. SQL Query Design - Date Range Help Needed
    By StevenCV in forum Queries
    Replies: 1
    Last Post: 02-28-2012, 08:24 AM
  5. Short date comparison
    By andy101 in forum Programming
    Replies: 2
    Last Post: 03-17-2011, 04:36 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