Found in [https://stackoverflow.com/questions/2561130/merge-overlapping-date-intervals] Merge overlapping date intervals Is there a better way of merging overlapping date intervals? The solution I came up with is so simple that now I wonder if someone else has a better idea of how this could be done. /***** DATA EXAMPLE *****/ DECLARE @ T TABLE ( d1 DATETIME , d2 DATETIME ) INSERT INTO @ T ( d1 , d2 ) SELECT '2010-01-01' , '2010-03-31' UNION SELECT '2010-04-01' , '2010-05-31' UNION SELECT '2010-06-15' , '2010-06-25' UNION SELECT '2010-06-26' , '2010-07-10' UNION SELECT '2010-08-01' , '2010-08-05' UNION SELECT '2010-08-01' , '2010-08-09' UNION SELECT '2010-08-02' , '2010-08-07' UNION SELECT '2010-08-08' , '2010-08-08' UNION SELECT '2010-08-09' , '2010-08-12' UNION SELECT '