Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 10th, 2006, 02:48 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Norway.
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:30 PM.


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