我在下面的表中使用sql server
AccID InvDate Debit Credit Remark
----------- ----------- --------- --------- ---------------
Salary_Exp 28-1-2017 1000 0 Pay salary M1
Cash 28-1-2017 0 1000 Pay salary M1
Salary_Exp 28-2-2017 2000 0 Pay salary M2
Cash 28-2-2017 0 2000 Pay salary M2
Salary_Exp 29-3-2017 1500 0 Pay salary M3
Cash 29-3-2017 0 1500 Pay salary M3
Salary_Exp 30-4-2017 1000 0 Pay salary M4
Cash 30-4-2017 0 1000 Pay salary M4
Salary_Exp 28-5-2017 3000 0 Pay salary M5
Cash 28-5-2017 0 3000 Pay salary M5
Salary_Exp 30-6-2017 1500 0 Pay salary M6
Cash 30-6-2017 0 1500 Pay salary M6
我想计算并显示每条记录的余额,如下所示 当我确定从日期到日期和AccID 例如 确定从29-3-2017到28-5-2017和AccId = Salary_Exp 我想在表格下面显示
InvDate Remark Debit Credit Balance
----------- ----------- --------- --------- ---------
- previous Balance 3000
29-3-2017 Pay salary M3 1500 0 4500
30-4-2017 Pay salary M4 1000 0 5500
28-5-2017 Pay salary M5 3000 0 8500
我正在使用存储过程
Create proc Entries_StatementOfAccount
@FromDate date,
@ToDate date,
@AccID nvarchar(15)
AS
SELECT InvDate,Remark,Debit,Credit,SUM(Debit-Credit) AS Balance
FROM Entries
WHERE AccID=@AccID and (InvDate between @FromDate and @ToDate)
ORDER BY InvDate
任何人都可以帮助我吗? 提前致谢