Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 10th, 2006, 02:48 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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






Similar Threads
Thread Thread Starter Forum Replies Last Post
MAX/MIN Value Help slbibs SQL Server 2005 4 November 6th, 2007 04:00 AM
MIN( MAX( UPDATE Stuart Stalker SQL Language 3 February 21st, 2007 07:10 AM
Problem with displaying ID when finding max or min marcin2k Access VBA 1 October 3rd, 2005 07:42 AM
Min / Max followup danbush XSLT 2 August 31st, 2005 12:02 PM
MAX and MIN ON TD cleytonjordan XSLT 7 July 27th, 2005 12:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.