Re: Square Peg in a Round Hole
- From: John Vinson <jvinson@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Dec 2006 20:37:52 -0700
On Thu, 28 Dec 2006 15:43:01 -0800, Andy6
<Andy6@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
my question is how do you test the EndDate of record 1 with the StartDate of
record 4 to give, car1 NOT AVAILABLE both times.
You need to compare both the StartDate and the EndDate of each record
with BOTH startdate and enddate of the other record. The overlap can
happen in four ways:
No overlap:
Record1 ____[_____]___________
Record2 ____________[______]__
Second starts during first:
Record1 ____[_____]___________
Record2 _______[_______]______
Second ends during first:
Record1 ____[_____]___________
Record2 _[______]_____________
Second entirely within first:
Record1 ____[_____]__________
Record2 ______[__]___________
A SQL query to detect any overlap would have
(A.StartDate >= B.StartDate AND A.StartDate <= B.EndDate])
OR
(A.EndDate >= B.StartDate AND A.EndDate <= B.EndDate])
OR
(B.StartDate >= A.StartDate AND B.StartDate <= A.EndDate])
OR
(B.EndDate >= A.StartDate AND B.EndDate <= A.EndDate])
John W. Vinson[MVP]
.
- References:
- Re: Square Peg in a Round Hole
- From: Gary Walter
- Re: Square Peg in a Round Hole
- From: Gary Walter
- Re: Square Peg in a Round Hole
- From: Andy6
- Re: Square Peg in a Round Hole
- Prev by Date: Re: Fill blanks with value from previous record
- Next by Date: Re: Fill blanks with value from previous record
- Previous by thread: Re: Square Peg in a Round Hole
- Next by thread: Re: Square Peg in a Round Hole
- Index(es):
Relevant Pages
|