Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

how to retrieve Min(startDate) and Max(endDate) for different groups of data? (sql server 2000)

$
0
0

My sample dataset (below) contains 3 groups -- 'a', 'b', 'c'.  I need to retrieve the Min(startDate) and Max(EndDate) for each group so that the output looks something like this (date format not an issue):

fk   minStart       maxEnd

a    1/13/1985    12/31/2003
b    2/14/1986    12/31/2003
c    4/26/1987    12/31/2002

What is the Tsql to perform this type of operation?  Note:  the actual data resides in a sql server 2000 DB.  If the Tsql is different between version 2000 and the later versions -- I would be grateful for both versions of the Tsql

------------------------------------------------------

--I noticed that multiple lines of Insert values doesn't work in Sql Server 2000 -- this sample is in Sql Server 2008

create table #tmp2(rowID int Identity(1,1), fk varchar(1), startDate datetime, endDate datetime)

insert into #tmp2
values
('a', '1/13/1985', '12/31/1999'),
('a', '3/17/1992', '12/31/1997'),
('a', '4/21/1987', '12/31/2003'),
('b', '2/14/1986', '12/31/2003'),
('b', '5/30/1993', '12/31/2001'),
('b', '6/15/1994', '12/31/2003'),
('b', '7/7/2001', '12/31/2003'),
('c', '4/26/1987', '12/31/1991'),
('c', '8/14/1992', '12/31/1998'),
('c', '9/10/1995', '12/31/2002'),
('c', '10/9/1996', '12/31/2000')

Thanks


Rich P



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>