# Datetime overlapping

I'm trying to determine the best way to approach this problem.  I have a series of conferences and I need to determine what conferences overlap on date and time.

Conference One  11/20/04 - 11/23/04  9:00AM - 4:00PM
Conference Two 11/21/04 - 11/22/04  9:00AM - 3:00PM
Conference Three 11/22/04 - 11/23/04  9:00AM - 5:00PM
Conference Four  11/20/04 - 11/23/04  9:00AM - 4:00PM

How do I determine my overlapping conferences?

Thanks for you help!
Paul
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
SELECT * FROM Table1 a WHERE EXISTS (SELECT 1 FROM Table1 WHERE a.StartDate BETWEEN StartDate AND EndDate)
0
Commented:
try that
0
Commented:
select A.Name, A.StartDate,A.endDate
from ConfTable as A
Where exists (Select b.name from confTable as B
where A.Name > B.Name
and  (
-- Starts before
(A.StartDate <= b.startDate
and A.EndDate >= b.startDate)
-- starts after and Ends before
or (A.endDate >= b.StartDate
and A.startDate <= b.enddate)
or (a.startdate < b.startDate
and a.enddate > b.enddate)
)
)

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Assistant Vice PresidentCommented:
Here's another possibility:

SELECT c2.Conference + ' overlaps ' + c1.Conference
FROM Conferences c1
INNER JOIN Conferences c2
ON c1.ConferenceID <> c2.ConferenceID
AND c1.StartDate < c2.StartDate
AND c1.EndDate > c2.StartDate
ORDER BY c2.ConferenceID,
c1.ConferenceID

Which, with the data you posted, would give this result:

Conference Two overlaps Conference One
Conference Two overlaps Conference Four
Conference Three overlaps Conference One
Conference Three overlaps Conference Two
Conference Three overlaps Conference Four

Since I didn't know how your conference data was stored, I used this table structure:

CREATE TABLE Conferences
(ConferenceID int NOT NULL,
Conference varchar (50),
StartDate datetime NULL,
EndDate datetime NULL,
CONSTRAINT PK_Conferences PRIMARY KEY  CLUSTERED (ConferenceID))

Jeff
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.