create proc pcStatMonth ( @tempmonth int, @tempyear int, @max int ) as insert into salemonth (P_Name,sumcell,I_IndentDate) select P_Name,sum(L_Value) as sumcell,day(I_IndentDate) as I_IndentDate from IndentList,Indent,Product where month(I_IndentDate)=@tempmonth and year(I_IndentDate)=@tempyear and L_I_ID=I_ID and L_Product=P_ID group by I_IndentDate,P_Name order by I_IndentDate ascinsert into StatMonth (P_Name) select DISTINCT P_Name from ProductDECLARE @sum NVARECHAR(20) DECLARE @Counter INT SET @Counter=1While (@Counter<=@max) BEGIN set @sum='sum' + counter exec('UPDATE StatMonth SET StatMonth.'+@sum+'=StatMonth.'+@sum+'+salemonth.sumcell, StatMonth.total=StatMonth.total+salemonth.sumcell FROM StatMonth,salmonth WHERE StatMonth.P_Name=salemonth.P_Name AND salemonth.I_IndentDate=@counter') END
(
@tempmonth int,
@tempyear int,
@max int
)
as
insert into salemonth (P_Name,sumcell,I_IndentDate)
select P_Name,sum(L_Value) as sumcell,day(I_IndentDate) as I_IndentDate
from IndentList,Indent,Product
where month(I_IndentDate)=@tempmonth
and year(I_IndentDate)=@tempyear
and L_I_ID=I_ID
and L_Product=P_ID
group by I_IndentDate,P_Name
order by I_IndentDate ascinsert into StatMonth (P_Name)
select DISTINCT P_Name from ProductDECLARE @sum NVARECHAR(20)
DECLARE @Counter INT
SET @Counter=1While (@Counter<=@max)
BEGIN
set @sum='sum' + counter
exec('UPDATE StatMonth
SET StatMonth.'+@sum+'=StatMonth.'+@sum+'+salemonth.sumcell,
StatMonth.total=StatMonth.total+salemonth.sumcell
FROM StatMonth,salmonth
WHERE StatMonth.P_Name=salemonth.P_Name
AND salemonth.I_IndentDate=@counter')
END