Finding min(FromDate) and max(ToDate)
Hi.
I have at table (in SQL-SErver 2005) with the following fields:
PlantId - varchar
FromDate - datetime
ToDate - datetime
Amount - decimal
I need to get a new table from this one with no overlapping periods. Say I have 3 rows where row 1 overlaps row 2 in regards to period, and that row 2 overlaps row 3. Is there a way, without using cursors, to get the lowest fromdate and highest Todate from these rows?
Example (dateformat = dd.mm.yyyy)
PlantID FromDate ToDate
100 15.05.2006 30.05.2006
100 20.05.2006 05.06.2006
100 02.06.2006 25.06.2006
100 25.06.2006 01.07.2006
100 01.07.2006 20.07.2006
From the above example-table, I would need to get the following result:
100 15.05.2006 25.06.2006
100 25.06.2006 01.07.2006
100 01.07.2006 20.07.2006
Anyone got an idea how to do this without cursors?
Thanks in advance
Gert
|