日期:2014-05-17 浏览次数:20754 次
CREATE PROCEDURE CustomerDetails.apf_CustMovement @CustId bigint,
@FromDate datetime, @ToDate datetime
AS
BEGIN
DECLARE @RunningBal money, @StillCalc Bit, @LastTran bigint
SELECT @StillCalc = 1, @LastTran = 0, @RunningBal = 0
WHILE @StillCalc = 1
BEGIN
SELECT TOP 1 @LastTran = t.TransactionId
FROM CustomerDetails.Customers c
JOIN TransactionDetails.Transactions t ON t.CustomerId = c.CustomerId
JOIN TransactionDetails.TransactionTypes tt ON
tt.TransactionTypeId = t.TransactionType
WHERE t.TransactionId > @LastTran
AND tt.AffectCashBalance = 1
AND DateEntered BETWEEN convert(varchar(30),@FromDate,121) AND convert(varchar(30),@ToDate,121)