sql - Dates that intersect -


I am researching this problem for a while and I can not come for a solution, hopefully Here's some help.

Currently, I am working with Microsoft SQL Server Management, I am trying to do the following:

First, the old inquiry will only return the results The last question in two dates is:

  SELECT e.Name, o.StartDate, o.EndDate to dbo.Name E, dbo.Date o where e.Name = o Name and o Start date & lt; = '2010-09-28 23:59:59' and Oandet & gt; = '2010- 9-28 00:00:00' and E. As a name 'A'  

Example table that is prepared after query (The real table is more clearly rows: P):

  Start Name 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  

Although we need to change it, so the query does the following:

Find the intersection dates for one day that are searched for the dates that are not the difference I do a day x

I have found a real useful site about this, but the date to compare the comparison is input, on the other hand, I have all the dates that are available to each other Do not bite each other.

Help Thanks for everyone

Dates that passage:

  SELECT E.name, O.start_date, O.end_date FROM dbo. Name E Inner Join Debo. Dates o on o.name = E.name and O.start_date & lt; @end_date and o.end_date & gt; @start_date WHERE E.name such as 'A'  

dates that are not intersecting are inversely in relation to dates:

  SELECT E. Name, O.start_date, O.end_date FROM dbo.names E INNER JOIN dbo.Dates oo o.name = E.name and (O.start_date> date_date or o.end_date & lt; @start_date) Where E.name Like 'A'  

I did not account for exact match dates. Decide how you want to deal with them and then adjust accordingly.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -