Results 1 to 5 of 5
  1. #1
    kagoodwin13 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    181

    Looking for overlap in dates between two records

    I have a database of logistics contracts. Each record is a shipping lane, with origin, destination, shipping rate between origin and destination, and effective dates for each rate.



    I'm trying to formulate a query to return when the same shipping lane has overlapping effective dates. This happens when an original contract has one date, but later an amendment to the contract changes the rate.

    For instance, if I'm shipping between Oshkosh, WI and Hackensack, NJ with Joe's Trucking, I may have one contract with an effective rate valid from 1/1/2010-12/31/2011. Later, Joe and I need to amend the contract to adjust for higher fuel prices, so I have a new rate between 7/1/2010-12/31/2011.

    pbaldy, if you're reading this, yes, I did refer to your overlap page on this matter. However, the string you recommend is a string I use in query to return valid contracts between those two dates. I think my particular problem is adding another layer of complexity.

    I referred to this website for help: http://allenbrowne.com/appevent.html and I'm using the following string:

    Code:
    NoClash: ([Table_1].[Effective Date] >= [Table].[End Date]) Or 
    ([Table_1].[End Date] <= [Table].[Effective Date]) Or 
    ([Table].[Carrier] <> [Table_1].[Carrier]) Or 
    ([Table].[Origin City] = [Table_1].[Origin City])
    In SQL it looks like so:
    Code:
    SELECT [Table].ID, [Table].[Origin City], [Table].[Dealer City], [Table].Carrier, [Table].[Effective Date], [Table].[End Date], [Table_1].ID, [Table_1].[Origin City], [Table_1].[Dealer City], [Table_1].Carrier, [Table_1].[Effective Date], [Table_1].[End Date], ([Table_1].[Effective Date]>=[Table].[End Date]) Or ([Table_1].[End Date]<=[Table].[Effective Date]) Or ([Table].[Carrier]<>[Table_1].[Carrier]) Or ([Table].[Origin City]=[Table_1].[Origin City])=[Table_1].[Carrier] AS NoClash
    FROM [Table], [Table] AS [Table_1]
    WHERE (((([Table_1].[Effective Date]>=[Table].[End Date]) Or ([Table_1].[End Date]<=[Table].[Effective Date]) Or ([Table].[Carrier]<>[Table_1].[Carrier]) Or ([Table].[Origin City]=[Table_1].[Origin City])=[Table_1].[Carrier])=False));
    The result I'm getting is not what I need though: it spits back every record of the table on the left side compared to record 1 on the right side. Basically that query is bunk.

    Any other ideas?

  2. #2
    kagoodwin13 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    181
    I solved this myself. The code from Allen Browne was correct. I just had to figure out which fields to query, and which to make = or <> (not equal). Lots of trial and error.

  3. #3
    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,726
    You want to post your solution and/or link to Allen Browne's good info? Others may read this in search of an answer.

  4. #4
    kagoodwin13 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    181
    Both the link and code are referenced in the original post.

  5. #5
    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,726

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-23-2012, 12:23 PM
  2. Finding the difference between the dates of two records
    By jamesborne in forum Programming
    Replies: 5
    Last Post: 01-19-2012, 06:48 PM
  3. Update dates for multiple (not all) records
    By thekruser in forum Access
    Replies: 2
    Last Post: 08-30-2010, 05:27 PM
  4. Counting Active Records Between 2 Dates
    By catat in forum Queries
    Replies: 5
    Last Post: 07-28-2010, 10:55 AM
  5. Replies: 0
    Last Post: 09-25-2006, 07:14 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