Overlapping and NonOverlapping dates.. (1 Viewer)

raghuprabhu

Registered User.
Local time
Today, 09:32
Joined
Mar 24, 2008
Messages
154
I have a table with the following fields

surName Text
commDate Date
ceaseDate Date
tableID Autonumber (Key)

The following are some sample records.

surName commDate ceaseDate ID
-------------------------------------------
Prabhu 01-Jan-12 15-Jan-12 1
Prabhu 16-Jan-12 24-Feb-12 2
Prabhu 18-Jan-12 21-Jan-12 3
Prabhu 16-Jan-12 21-Feb-12 4
Prabhu 19-Jan-12 20-Feb-12 5
Prabhu 01-Feb-12 20-Feb-12 6
Prabhu 01-Mar-12 31-May-12 7
Prabhu 12-Apr-12 30-Apr-12 8
Prabhu 15-Jun-12 30-Jun-12 9

I want to design a query named "OverlappingDates" which should show all the records 2 to 8 and another one named "nonOverlappigDates" which should show recrods 1 and 9.

Any ideas?

Thanks in advance.

Raghu Prabhu
Melbourne.
 

Taruz

Registered User.
Local time
Today, 17:32
Joined
Apr 10, 2009
Messages
168
Hi..:

for OverlappingDates..:

Code:
[B][I][COLOR="Navy"]select 
surName
, commDate
, ceaseDate
, ID
from tablename
where 
ID<>(select last(ID) from tablename) 
   and 
ID<>(select first(ID) from tablename)[/COLOR][/I][/B]

this for nonOverlappigDates:

Code:
[B][I][COLOR="Indigo"]select 
surName
, commDate
, ceaseDate
, ID
from tablename
where 
ID =(select last(ID) from tablename) 
   or 
ID =(select first(ID) from tablename)[/COLOR][/I][/B]

i not limit count of records..
 

philben

Registered User.
Local time
Today, 18:32
Joined
Jan 30, 2011
Messages
23
Hi,

Overlapping query (qrOverlapping) :
Code:
SELECT DISTINCT T.*
FROM overlapping AS T, overlapping AS T2
WHERE (T.commDate<=t2.commdate And T.ceaseDate>=t2.commdate And T.ID<>T2.ID) Or
      (T.commDate Between t2.commdate And t2.ceaseDate And T.ID<>T2.ID) Or
      (T.ceaseDate Between t2.commdate And t2.ceaseDate And T.ID<>T2.ID);

NonOverlapping query :
Code:
SELECT overlapping.*
FROM overlapping LEFT JOIN qrOverlapping ON overlapping.ID = qrOverlapping.ID
WHERE qrOverlapping.ID Is Null;

regards,

Philippe
 

philben

Registered User.
Local time
Today, 18:32
Joined
Jan 30, 2011
Messages
23
it's possible to improve the performance of the first query (qroverlapping) :

Code:
SELECT T.Id, T.surName, T.commDate, T.ceaseDate
FROM overlapping AS T, overlapping AS T2
WHERE (T.commDate<=[t2].[ceaseDate] AND T.ceaseDate>=[t2].[commdate] AND T.ID<>[T2].[ID])
GROUP BY T.Id, T.surName, T.commDate, T.ceaseDate;
 

raghuprabhu

Registered User.
Local time
Today, 09:32
Joined
Mar 24, 2008
Messages
154
Hi philben,

I have attached the database with the table. I have tried to do the query and it is not working. May be my syntext is incorrect.

Please have a look my attached database.

Thanks

Raghu
 

Attachments

  • testOverlappingDates.zip
    12.2 KB · Views: 86

philben

Registered User.
Local time
Today, 18:32
Joined
Jan 30, 2011
Messages
23
I added queries to your database.

See attached.

Philippe
 

Attachments

  • testOverlappingDatesWithQueries.zip
    12 KB · Views: 110

raghuprabhu

Registered User.
Local time
Today, 09:32
Joined
Mar 24, 2008
Messages
154
Thanks a lot philben!

I was able to use your designed query and make my life a bit easier.

Well, I am still learning Access and will be learning till my last breath!

Cheers
Raghuprabhu
 

Users who are viewing this thread

Top Bottom