Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
avijit_mca
Posting Yak Master
109 Posts |
Posted - 2010-04-24 : 08:25:32
|
| Tab1id sdate edate1 01/01/10 03/03/101 25/01/10 25/03/101 02/03/10 25/04/101 26/04/10 30/05/102 01/01/10 03/03/102 25/01/10 25/03/103 02/03/10 25/04/104 26/04/10 30/05/10i want to find out id details who have over lap date range with same id.eg. 1 01/01/10 03/03/101 25/01/10 25/03/101 02/03/10 25/04/10first 3 colum in the table. not 4th colum in the table.what is the best solution(best query performance) are available.regards,AvijitRegards,avijit |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-24 : 08:33:40
|
| [code]SELECT t.id,t.sdate,t.edateFROM Table tOUTER APPLY (SELECT COUNT(1) AS Cnt FROM Table WHERE id = t.id AND ((sdate >= t.sdate AND sdate <= t.edate) OR (sdate <= t.sdate AND edate >= t.sdate)) )t1WHERE t1.Cnt >0[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
avijit_mca
Posting Yak Master
109 Posts |
Posted - 2010-04-24 : 09:52:52
|
quote: Originally posted by visakh16
SELECT t.id,t.sdate,t.edateFROM Table tOUTER APPLY (SELECT COUNT(1) AS Cnt FROM Table WHERE id = t.id AND ((sdate >= t.sdate AND sdate <= t.edate) OR (sdate <= t.sdate AND edate >= t.sdate)) )t1WHERE t1.Cnt >0 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
ThanksRegards,avijit |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-24 : 11:05:58
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|