Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Declare the proper datatypes for these to match up with how they're
- -- defined in the database I'm just guessing on these
- DECLARE @AppID INT;
- DECLARE @Term INT;
- DECLARE @FinanaceAmount MONEY;
- DECLARE @IntRate DECIMAL(5, 3);
- -- Creates a way to grab data from the SELECT statement
- DECLARE Loan_Cursor CURSOR FOR
- SELECT AppID,
- Term,
- FinanceAmount,
- IntRate
- FROM LOANTABLENAME;
- -- Start grabbing the data
- OPEN Loan_Cursor;
- FETCH NEXT FROM Loan_Cursor INTO @AppID, @Term, @FinanceAmount, @IntRate;
- -- Keep doing this until we can no longer grab anymore data
- WHILE @@FETCH_STATUS = 0
- BEGIN
- -- Calcuate various loan variables and set our counter
- DECLARE @I = 0;
- DECLARE @OutstandingBalance = @FinanceAmount;
- DECLARE @MonthlyAmount = @FinanceAmount / @Term;
- DECLARE @InterestPaid = @MonthlyAmount * @IntRate;
- WHILE @I < @TERM -- This should create @Term number of rows
- BEGIN
- -- I may have messed up on calucalting the outstanding balance
- @OutstandingBalance = @OutstandingBalance - @MonthlyAmount;
- INSERT INTO CUSTOMERPAYMENTTABLENAME (AppID, --Reference back to the app I assume is needed
- IntrestPaid,
- PrincipalPaid,
- OutstandingBalance
- VALUES (@AppID,
- @IntrestPaid,
- @MonthlyAmount - @IntrestPaid, --Prinicipal paid
- @OustandingBalance
- )
- END
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement