my view is set up like a check register.
Problem 1:
I have a transactiondate field and a nextTdate field where the transactiondate is the date the item was entered into the system and the nextTdate is to be based off of the next rows transactiondate. If no next row exists then use todaysdate.
Problem 2:
Im trying to do a running balance in the view. Each BuyAmountPayment should subtract off of the originalamount - previous payments made. This way when the balance is 0 they are all paid. How do i do a running balance in a view?
My View
SELECT M.LoanID, P.HistoryCounter, M.OriginalBuyAmount, M.DatePaidOff, M.OpenDate, P.BuyAmountPayment, P.TransactionDate, P.TransactionCode,
P.PayDownInterest,
(SELECT P2.TransactionDate
FROM dbo.iSplit_BuyAmount_Payments P2
WHERE P2.LoanID = P.LoanID AND P2.HistoryCounter = P.HistoryCounter) AS NextTDate,
M.OriginalBuyAmount - P.BuyAmountPayment AS Balance, dbo.iSplit_InterestRate.BuyAmountRate * .01 AS InterestRate
FROM dbo.iSplit_BuyAmount_Main M INNER JOIN
dbo.iSplit_BuyAmount_Payments P ON M.LoanID = P.LoanID INNER JOIN
dbo.iSplit_InterestRate ON M.LoanID = dbo.iSplit_InterestRate.LoanID
WHERE (P.PayDownInterest = 1)
Problem 1:
I have a transactiondate field and a nextTdate field where the transactiondate is the date the item was entered into the system and the nextTdate is to be based off of the next rows transactiondate. If no next row exists then use todaysdate.
Problem 2:
Im trying to do a running balance in the view. Each BuyAmountPayment should subtract off of the originalamount - previous payments made. This way when the balance is 0 they are all paid. How do i do a running balance in a view?
My View
SELECT M.LoanID, P.HistoryCounter, M.OriginalBuyAmount, M.DatePaidOff, M.OpenDate, P.BuyAmountPayment, P.TransactionDate, P.TransactionCode,
P.PayDownInterest,
(SELECT P2.TransactionDate
FROM dbo.iSplit_BuyAmount_Payments P2
WHERE P2.LoanID = P.LoanID AND P2.HistoryCounter = P.HistoryCounter) AS NextTDate,
M.OriginalBuyAmount - P.BuyAmountPayment AS Balance, dbo.iSplit_InterestRate.BuyAmountRate * .01 AS InterestRate
FROM dbo.iSplit_BuyAmount_Main M INNER JOIN
dbo.iSplit_BuyAmount_Payments P ON M.LoanID = P.LoanID INNER JOIN
dbo.iSplit_InterestRate ON M.LoanID = dbo.iSplit_InterestRate.LoanID
WHERE (P.PayDownInterest = 1)