日期:2014-05-16  浏览次数:20626 次

一个存储过程,望大神能帮助小弟【急求】
首先对需求进行描述:该存储过程不会涉及到表的操作,得到1到12月每个月的金额。
       需求详情:给出参数1、每年的金额;2、开始时间;3、结束时间;如:每年的金额Amount=3000.00;开始时间StartDate='2008-08-01';结束时间EndDate=’2010-06-01‘;
       需求结果:1、得到每年每月的金额,如:08年8月--08年12月(09年1月--09年12月)(10年1月--10年5月)每个月的金额(该金额(3000)分配是平均分配,如果出现余数则将余数加到该年的最后一个月上面)
                           2、得到该时间内的总金额(每年最后一个月的金额+每年前面月份的金额);
                           3、最后使用临时表展示数据结果
望大神们能抽出您宝贵的时间,小弟感激不尽!!!
------解决方案--------------------
第68行改为
set @str='Update #table set '+@Name+' = ('+cast(@Amount/@EndMonth as varchar(100))+'+('+cast(@Amount as varchar(100))+'-(isnull(Amount1,0)+isnull(Amount2,0)+isnull(Amount3,0)+isnull(Amount4,0)+isnull(Amount5,0)+isnull(Amount6,0)+isnull(Amount7,0)+isnull(Amount8,0)+isnull(Amount9,0)+isnull(Amount10,0)+isnull(Amount11,0)))) where Year ='+ltrim(DATENAME(Year,@Enddate));