Home Forums SQL Server 2005 T-SQL (SS2K5) Calculate Past Due Principal and Past Due Interest Based on Due Dates RE: Calculate Past Due Principal and Past Due Interest Based on Due Dates

  • Hi, am new for this forum, so couldn't post properly...

    1. This is my table

    CREATE TABLE [dbo].[tblWeeklyTransactionSheet](

    [ID] [int] IDENTITY(1,1) NOT NULL,

    [Period] [float] NOT NULL,

    [PayDate] [smalldatetime] NOT NULL,

    [Payment] [decimal](12, 2) NOT NULL,

    [Current_Balance] [decimal](12, 2) NOT NULL,

    [Interest] [decimal](12, 2) NOT NULL,

    CONSTRAINT [PK_tblWeeklyTransactionSheet] PRIMARY KEY CLUSTERED

    (

    [ID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    2. this is my Stored Procedure to Shedule Weekly Trsansaction Sheet

    ALTER PROCEDURE [dbo].[Sp_SelectWeeklyTransactionSheet]

    -- Add the parameters for the stored procedure here

    AS

    BEGIN

    Declare

    @loan decimal(12,2,

    @InterestRate FLOAT,

    @PeriodInWeeks FLOAT,

    @PaymentStartDate SMALLDATETIME,

    @Particular varchar(20) ,

    @PaidAmount decimal(12,2),

    @Payment decimal(12,2),

    @Period FLOAT,

    @CompoundingPeriod FLOAT,

    @CompoundingInterest FLOAT,

    /*** CALCULATED LOAN VARIABLES ***/

    @CurrentBalance decimal(12,2),

    @interest FLOAT,

    /*** Loan TIME VARIABLES ***/

    @LoanPaymentEndDate SMALLDATETIME,

    @LoanPayDate SMALLDATETIME,

    @LoanDueDate SMALLDATETIME ,

    /*** USER VARIABLES ***/

    SET @InterestRate = @InterestRate/100

    SET @CompoundingPeriod = 12

    SET @loan =20,000

    SET @PeriodInWeeks = 10

    SET @PaymentStartDate = '2012-09-13 00:00:00'

    /*** END USER VARIABLES ***/

    SET @CompoundingInterest = @InterestRate/@CompoundingPeriod

    SET @Payment = @loan / @PeriodInWeeks

    SET @Period = 1

    SET @LoanPaymentEndDate = DATEADD(WEEK,@PeriodInWeeks,@PaymentStartDate)

    SET @LoanPayDate = @PaymentStartDate

    BEGIN

    WHILE (@Period < = @PeriodInWeeks)

    BEGIN

    SET @CurrentBalance = @Payment +@Interest

    SET @interest = 0

    SET @LoanDueDate = @LoanPayDate

    insert into tblWeeklyTransactionSheet(Period, PayDate,Payment,Current_Balance,Interest)

    SELECT

    @col_WeeklyID,

    @col_ApplicantNumber,

    @Period,

    @LoanDueDate,

    @Payment,

    @CurrentBalance,

    @interest,

    @PaidAmount

    SET @Period = @Period + 1

    SET @LoanPayDate = DATEADD(WK,1,@LoanPayDate)

    END

    END

    select col_WeeklyID,col_ApplicantNumber,Period as Installments, PayDate,Payment,PaidAmount,Interest,Current_Balance from tblWeeklyTransactionSheet

    END

    3. Am getting shedule table, but i need to calculate Due Interest + Due Amount for if non payable based on due date, INITIALLY INTEREST WILL BE 0 (for regular payment),

    Thanks

    Shiva Reddy