sqlserver存储过程 计算当天收支的期初期末即上次结余和本次结余方法分享
create proc liushui
as
declare @datestart datetime ---开始计算日期
set @datestart ='2018-08-01'
declare @qcomney money --期初
set @qcomney =100
--inpu 收入 outpu 支出 riqi 日期
select t1.riqi 日期 ,sum(t2.inpu-t2.outpu)+@qcomney-(t1.inpu-t1.outpu) 期初, t1.inpu 收入,t1.outpu 支出
,sum(t2.inpu-t2.outpu)+@qcomney 期末
from shouzhi t1,shouzhi t2
where t1.riqi>=t2.riqi
and t1.riqi >=@datestart
group by t1.riqi,t1.inpu,t1.outpu
order by t1.riqi;
go
本文来自博客园,作者:周周渡劫ing,转载请注明原文链接:https://www.cnblogs.com/zzordering/p/17562328.html

浙公网安备 33010602011771号