A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Find Records that ovelap



 
 
Thread Tools Display Modes
  #1  
Old May 25th, 2004, 07:11 AM
John H
external usenet poster
 
Posts: n/a
Default Find Records that ovelap

I have a table with 2 date fields startdate and enddate. They vaules are long int in yyyymmdd format.

I want to check for any overlap between records.

Eg if record 1 starts on 20040501 and ends on 20040530 and record 2 starts on 20040515 there is overlap between these records.

John H

  #2  
Old May 25th, 2004, 12:51 PM
Gary Walter
external usenet poster
 
Posts: n/a
Default Find Records that ovelap


"John H" wrote
I have a table with 2 date fields startdate and enddate. They vaules are long int

in yyyymmdd format.

I want to check for any overlap between records.

Eg if record 1 starts on 20040501 and ends on 20040530 and record 2 starts on

20040515 there is overlap between these records.

Hi John,

Michel once explained overlap so succinctly,
I quote him he

Ranges do NOT overlap if
( I assume aStart, aEnd, bStart and bEnd are the intervals):

aStart bEnd OR aEnd bStart

they overlap, in part or in full, on the negation of that statement, ie
(Apply De Morgan's law) :

aStart = bEnd AND aEnd = bStart

end quote

If I understand correctly, you want a query that will
look at all the records in the table and find the ones
that overlap.

One possible method might be to bring the table
twice into your query,

set alias of one to "a", the other to "b",

no join (Cartesian join),

bring a.StartDate, a.EndDate, b.StartDate, b.EndDate
down into field rows of grid,

then use above in WHERE clause
(but maybe also add clause to weed out where they
are both equal, maybe you won't need this)

SELECT
a.StartDate,
a.EndDate,
b.StartDate,
b.EndDate
FROM yourtable AS a, yourtable AS b
WHERE
(a.StartDate = b.EndDate
AND
a.EndDate = b.StartDate)
AND
(a.StartDate b.StartDate
AND
a.EndDate b.EndDate);

This is untested, but hopefully this will get
you started if something not quite right.
Of course you can add other fields from
your a and b table.

Good luck,

Gary Walter







 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:10 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.