CREATE TABLE WorkTimeLog
(
WTLID int identity NOT NULL,
HourWork numeric(7,2) NOT NULL,
MonthStart datetime NOT NULL,
PRIMARY KEY(WTLID)
)
go
set dateformat dmy;
insert WorkTimeLog values (366.00, '01-May-2010')
insert WorkTimeLog values (1000.00, '01-Sep-2010')
insert WorkTimeLog values (1704.00, '01-Oct-2010')
insert WorkTimeLog values (3000.00, '01-Nov-2010');
go
select IsNull((select HourWork from WorkTimeLog where MonthStart = wtl.MonthStart) + (select HourWork from WorkTimeLog where MonthStart = (select MAX(MonthStart) from WorkTimeLog where MonthStart < wtl.MonthStart)), wtl.HourWork) as PairTotal,
RIGHT(CONVERT(char(11), wtl.MonthStart, 13), 8) as Period
from WorkTimeLog as wtl
order by wtl.MonthStart
go
PairTotal Period
366.00 May 2010
1366.00 Sep 2010
2704.00 Oct 2010
4704.00 Nov 2010