SQL: Merge Date Ranges
===

I've a table, which describes work slices of a business working calendar: (date format is 24 hours format)

<pre>
PK  | STARTDATE          | ENDDATE
__________________________________________
1   | 2012/07/21 02:00   | 2012/07/21 04:00
2   | 2012/07/21 03:00   | 2012/07/21 10:00
3   | 2012/07/21 06:00   | 2012/07/21 17:00
4   | 2012/07/21 18:00   | 2012/07/21 19:00

</pre>

Now, I like to merge the date ranges (within a given start and end date) like this:

<pre>
PK  | STARTDATE          | ENDDATE
__________________________________________
1   | 2012/07/21 02:00   | 2012/07/21 17:00
2   | 2012/07/21 18:00   | 2012/07/21 19:00
</pre>

Is there a way to do this with SQL97 standard? If so, what is with other operations (e.g. if I want to to an invered merge, the result should be [2012/07/21 00:00 | 2012/07/21 02:00] and [2012/07/21 19:00 | 2012/07/22 00:00]).

Best regards!



