Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Comparing date times start time and end time using between

Posted on 2010-09-09
6
Medium Priority
?
356 Views
Last Modified: 2012-05-10
I cant seem to get the right combination to generate the proper results.  I need to compare the start date and end date to determine if rows are overlaping.  Example

RowID        StartTime                           EndTime
1                9/11/2010  08:00:00         9/11/2010  09:00:00
2                9/11/2010  07:30:00         9/11/2010  08:30:00
3                9/11/2010  08:30:00         9/11/2010  09:30:00
4                9/11/2010  09:30:00         9/11/2010  10:30:00

I need to return row 1,2 and 3 but not row 4 since the start time is the same as the end time of the previous appointment. Any help is greatly appreciated.
0
Comment
Question by:clintnash
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 20

Expert Comment

by:dsacker
ID: 33638162
Try this:
select RowID,
       StartTime,
       EndTime
from   MyTable
where  StartTime NOT IN (select EndTime from MyTable)

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33638280
what about this:
select t.*
 from yourtable t
 where exists( select null from yourtable o where o.starttime < t.endtime and o.endtime > t.starttime )

Open in new window

0
 
LVL 3

Accepted Solution

by:
mehdi_javan earned 2000 total points
ID: 33638466
I think you need this:

Select t1.* 
from YourTable t1
where exists (select null from YourTable t2
              where (t1.StartTime > t2.StartTime and t1.StartTime < t2.EndTime)
              or (t1.EndTime > t2.StartTime and t1.EndTime < t2.EndTime)
              or (t1.StartTime < t2.StartTime and t1.EndTime > t2.EndTime)

Open in new window

0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 1

Author Closing Comment

by:clintnash
ID: 33638666
Short of a missing ) at the end, this query returns the correct results. Thanks to each of your for your help this morning.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33638677
did you try mine? did it not work?
0
 
LVL 1

Author Comment

by:clintnash
ID: 33639633
Angel, Actually I tried them all, the first returned two of the three rows, yours returned all four rows.  Thank you...
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question