SQL2000.
I have a dataset:
seqNum value
1 30.25
2 31.25
3 32.25
4 30.00
5 28.30
6 29.50
7 28.00
8 28.00
9 28.00
10 28.00
11 28.00
I am trying to write a sql statement that returns each record + checks 5 sequence #'s forward and returns the maximum value.
So, my result set should be:
seqNum value max5DayValue
1 30.25 32.25
2 31.25 32.25
3 32.25 32.25
4 30.00 30.00
5 28.30 29.50
6 29.50 29.50
Not sure why I'm stumped - seems straightforward enough...I hope I can avoid a cursor...
Thanks.
I have a dataset:
seqNum value
1 30.25
2 31.25
3 32.25
4 30.00
5 28.30
6 29.50
7 28.00
8 28.00
9 28.00
10 28.00
11 28.00
I am trying to write a sql statement that returns each record + checks 5 sequence #'s forward and returns the maximum value.
So, my result set should be:
seqNum value max5DayValue
1 30.25 32.25
2 31.25 32.25
3 32.25 32.25
4 30.00 30.00
5 28.30 29.50
6 29.50 29.50
Not sure why I'm stumped - seems straightforward enough...I hope I can avoid a cursor...
Code:
if exists (select id from tempdb..sysobjects where id=object_id('tempdb..#tbl1'))
DROP table #tbl1
select 1 as seqNum,30.25 as value into #tbl1
insert into #tbl1 select 2,32.25
insert into #tbl1 select 3,32.25
insert into #tbl1 select 4,30.00
insert into #tbl1 select 5,28.30
insert into #tbl1 select 6,29.50
insert into #tbl1 select 7,28.00
insert into #tbl1 select 8,28.00
insert into #tbl1 select 9,28.00
insert into #tbl1 select 10,28.00
insert into #tbl1 select 11,28.00
select * from #tbl1 order by seqNum
Thanks.