Dates that intersect
Posted
by MikeAbyss
on Stack Overflow
See other posts from Stack Overflow
or by MikeAbyss
Published on 2010-06-15T17:29:50Z
Indexed on
2010/06/15
17:32 UTC
Read the original article
Hit count: 174
Hi everyone,
I've been researching this problem for awhile now and I can't seem to come to a solution, hopefully someone here can help.
Currently I'm working with Microsoft SQL server management, I've been trying to do the following:
Previously, the old query would just return the results that fit between two dates Heres the previous query:
SELECT e.Name, o.StartDate, o.EndDate
FROM dbo.Name e, dbo.Date o
WHERE
where e.Name = o.Name
and o.StartDate <= '2010-09-28 23:59:59'
and o.EndDate >= '2010-9-28 00:00:00'
and e.Name like 'A'
Example table that is produced after the query runs (The real table has a lot more rows obviously :P) :
Name Start End
A 2010-09-28 07:00:00 2010-09-28 17:00:00
A 2010-09-28 13:45:00 2010-09-28 18:00:00
A 2010-09-28 08:00:00 2010-09-28 16:00:00
A 2010-09-28 07:00:00 2010-09-28 15:30:00
However we need to change this, so that the query does the following:
find the dates that intersect for a day x find the dates that don't intersect for a day x
I've found a real useful site regarding this http://bloggingabout.net/blogs/egiardina/archive/2008/01/30/check-intersection-of-two-date-ranges-in-sql.aspx However the date to compare against is inputted, mine on the other hand has to all dates that intersect/don't intersect.
Thanks for the help everyone.
© Stack Overflow or respective owner