DECLARE
@LoanAmount MONEY = '5000000.00'
,@ROI FLOAT = 11
,@Tenure NUMERIC(18,2) = 12
,@Period INT
,@Principal MONEY
,@Interest MONEY
,@EMI MONEY
,@AMT MONEY
SET @Period = 1
SET @ROI = (@ROI/100)/12
DECLARE
@EMI_TABLE TABLE
(PERIOD INT,PAYDATE SMALLDATETIME,EMI MONEY,PRINCIPAL MONEY,INTEREST MONEY ,BALANCE MONEY)
--EMI = [P x R x (1 + R)^N] / [(1 + R)^N - 1]
SELECT @EMI = ROUND((@LoanAmount * @ROI * POWER((1 + @ROI), @Tenure)) / (POWER((1 + @ROI), @Tenure) - 1),2)
WHILE @Period <= @Tenure
BEGIN
--INTEREST
= [P x R]
SELECT
@Interest = ROUND((@LoanAmount * @ROI),2)
--PRINCIPAL
= [EMI - INTEREST]
SELECT
@Principal = ROUND((@EMI - @Interest),2)
--OUTSTANDING
LOAN AMOUNT = [@LoanAmount - Principal]
SELECT
@LoanAmount = ROUND((@LoanAmount -
@Principal),2)
INSERT
INTO @EMI_TABLE VALUES(@Period,DATEADD(MM,@Period,GETDATE()),@EMI,@Principal,@Interest,@LoanAmount)
SET
@Period = @Period +
1
END
SELECT * FROM @EMI_TABLE
Output
P - Loan Amount
R - Rate of Interest
N - Tenure/Loan Period
R - Rate of Interest
N - Tenure/Loan Period
You will get different in paisa. Need to manage as per requirement.