Consulting

Results 1 to 3 of 3

Thread: Query join table with date intervals

  1. #1
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    291
    Location

    Query join table with date intervals

    Hi,

    I have a table which calculates the number of days in a transaction as [EndDate]-[StartDate] as numdays

    I have another table with time intervals eg:-


    1 Overnight
    7 1 Week
    30 1 month
    90 3 months


    How do I join these two table so that I can return the time interval based on numdays


    Thanks
    Phil

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Phil, I am not sure how you do what you want as the number of days will only meet some of your intervals some of the time.
    Can you explain a bit more about what you are trying to do.

  3. #3
    I would use a subquery to lookup the value from the other table. I would also change your interval table to have a range.


    See: Subquery Basics


    Another option would be to create a User Defined Function (UDF). You can pass it the "days" and it would return the interval. The advantage to the UDF is that is can be sharted. You can use the same UDF in forms, reports, and queries.

    I prefer to do this type of calculation at the form or report level because it generally has better performance.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

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