Y
ymg1103
Unregistered / Unconfirmed
GUEST, unregistred user!
Create Procedure yebbrowse
@cyear Int,
@cmonth Int
AS
--创建临时表
Declare @t Table(
个人账号 Varchar(20) Not Null,
单位缴存 Numeric(18,2),
个人缴存 Numeric(18,2),
转入金额 Numeric(18,2),
支取金额 Numeric(18,2),
利息 Numeric(18,2),
余额 Numeric(18,2),
其中利息总额 Numeric(18,2)
)
Insert Into @t
select 个人账号,SUM(单位缴存) AS 单位缴存,SUM(个人缴存) AS 个人缴存,SUM(转入金额) AS 转入金额,
SUM(支取金额) AS 支取金额,SUM(利息) AS 利息,SUM(余额) AS 余额,SUM(其中利息总额) AS 其中利息总额 FROM
gjj WHERE (年份<=@cyear OR 年份 is null) AND (月份<=@cmonth or 月份 is null) GROUP BY 个人账号
Update @t Set 余额=ISNULL(余额,0)+ISNULL(单位缴存,0)+ISNULL(个人缴存,0)+ISNULL(转入金额,0)-ISNULL(支取金额,0)+ISNULL(利息,0)
Update @t Set 其中利息总额=ISNULL(其中利息总额,0)+ISNULL(利息,0)
Delete from yeb
Insert Into yeb
Select a.部门,a.个人账号,a.姓名,a.单位缴存,a.个人缴存,a.转入金额,a.支取金额,a.利息,b.余额,b.其中利息总额,a.是否封存,a.封存日期 from gjj a
Left Outer Join @t b On a.个人账号=b.个人账号 Where a.年份=@cyear And a.月份=@cmonth
@cyear Int,
@cmonth Int
AS
--创建临时表
Declare @t Table(
个人账号 Varchar(20) Not Null,
单位缴存 Numeric(18,2),
个人缴存 Numeric(18,2),
转入金额 Numeric(18,2),
支取金额 Numeric(18,2),
利息 Numeric(18,2),
余额 Numeric(18,2),
其中利息总额 Numeric(18,2)
)
Insert Into @t
select 个人账号,SUM(单位缴存) AS 单位缴存,SUM(个人缴存) AS 个人缴存,SUM(转入金额) AS 转入金额,
SUM(支取金额) AS 支取金额,SUM(利息) AS 利息,SUM(余额) AS 余额,SUM(其中利息总额) AS 其中利息总额 FROM
gjj WHERE (年份<=@cyear OR 年份 is null) AND (月份<=@cmonth or 月份 is null) GROUP BY 个人账号
Update @t Set 余额=ISNULL(余额,0)+ISNULL(单位缴存,0)+ISNULL(个人缴存,0)+ISNULL(转入金额,0)-ISNULL(支取金额,0)+ISNULL(利息,0)
Update @t Set 其中利息总额=ISNULL(其中利息总额,0)+ISNULL(利息,0)
Delete from yeb
Insert Into yeb
Select a.部门,a.个人账号,a.姓名,a.单位缴存,a.个人缴存,a.转入金额,a.支取金额,a.利息,b.余额,b.其中利息总额,a.是否封存,a.封存日期 from gjj a
Left Outer Join @t b On a.个人账号=b.个人账号 Where a.年份=@cyear And a.月份=@cmonth