Sql server 2005 使用sql server 2005进行月累计和
我的表格中有如下数据:Sql server 2005 使用sql server 2005进行月累计和,sql-server-2005,Sql Server 2005,我的表格中有如下数据: > HourWork MonthName > > 366.00 May 2010 > 1000.00 Sep 2010 > 1704.00 Oct 2010 > 3000.00 Nov 2010 现在,我想制作一个存储过程来获得以下结果: > HourWork MonthName > > 366.00 May 2010 > 1366.00 Se
> HourWork MonthName
>
> 366.00 May 2010
> 1000.00 Sep 2010
> 1704.00 Oct 2010
> 3000.00 Nov 2010
现在,我想制作一个存储过程来获得以下结果:
> HourWork MonthName
>
> 366.00 May 2010
> 1366.00 Sep 2010
> 2704.00 Oct 2010
> 4704.00 Nov 2010
意味着获取下个月的值,以及当前月份的数据
任何人都可以告诉我如何使用存储过程得到这样的结果
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