私は次のように書いていますstored procedure
が、エラーが発生します。ありがとう。
/* stored procedure interestcalc writen by M */
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE PROCEDURE spInterestCal
(
@P_NO INT,
@TOTAL_MONEY INT,
@PAYMENT_TYPE INT, /* if payment type is 1 then Yearly, 2 then Semi Yearly, 3 then Quaterly, 4 then Montly */
@INTEREST_RATE INT,
@START_DATE DATE,
@END_DATE DATE,
)
AS
BEGIN
DECLARE @INSTALLMENT_FACTOR FLOAT
DECLARE @INSTALLMENT_NUMBER INT
DECLARE @INTEREST FLOAT
DECLARE @I INT
DECLARE @R_INSTALLMENT_NUMBER INT
SET @INSTALLMENT_FACTOR = 0
SET @INSTALLMENT_NUMBER = 0
SET @INTEREST = 0
SET @I = 1
SET @R_INSTALLMENT_NUMBER = 0
/*
DECLARE @YEARS_DIFF INT
DECLARE @MONTHS_DIFF INT
DECLARE @DAYS_DIFF INT
SET @YEARS_DIFF = DATEDIFF(YYYY,@START_DATE,@END_DATE)
SET @MONTHS_DIFF = DATEDIFF(M,@START_DATE,@END_DATE)-(datediff(YYYY,@START_DATE,@END_DATE)*12)
SET @DAYS_DIFF = DATEPART(D,@END_DATE)-DATEPART(D,@START_DATE)
*/
IF (@PAYMENT_TYPE = 1) /* if PaymentType is 1 means Yearly */
BEGIN
SELECT @INSTALLMENT_FACTOR = 1;
SELECT @INSTALLMENT_NUMBER = 1; /*Yearly So 1 INSTALLMENT */
END
IF (@PAYMENT_TYPE = 2) /* if PaymentType is 2 means Semi Yearly */
BEGIN
SELECT @INSTALLMENT_FACTOR = 0.5;
SELECT @INSTALLMENT_NUMBER = 2; /*Semi Yearly So 2 INSTALLMENT */
END
IF (@PAYMENT_TYPE = 3) /* if PaymentType is 3 means Quaterly */
BEGIN
SELECT @INSTALLMENT_FACTOR = 0.25;
SELECT @INSTALLMENT_NUMBER = 4; /*Quaterly So 4 INSTALLMENT */
END
IF (@PAYMENT_TYPE = 4) /* if PaymentType is 4 means Montly */
BEGIN
SELECT @INSTALLMENT_FACTOR = 0.08;
SELECT @INSTALLMENT_NUMBER = 12; /*Montly So 12 INSTALLMENT */
END
SELECT @R_INSTALLMENT_NUMBER = ((SELECT DATEDIFF(YEAR, @START_DATE, @END_DATE))* @INSTALLMENT_NUMBER)
DECLARE @SMOUNT INT
DECLARE @SYEAR INT
SELECT @SMOUNT = (SELECT MONTH(@START_DATE))
SELECT @SYEAR = (SELECT YEAR(@START_DATE))
WHILE ((SELECT @I) < = @R_INSTALLMENT_NUMBER ) /* Calculates Interest And Prints Info*/
BEGIN
IF (@SMOUNT > 12)
BEGIN
SELECT @SYEAR +1
END
SELECT @R_INSTALLMENT_NUMBER = @R_INSTALLMENT_NUMBER -1
SELECT @INTEREST = ((SELECT @TOTAL_MONEY) - (SELECT @R_INSTALLMENT_NUMBER * (SELECT @INSTALLMENT_FACTOR*(SELECT @TOTAL_MONEY)))) * ((SELECT @INTEREST_RATE)/100 )
PRINT ' P_NO IS ' + @P_NO + ' TOTAL_MONEY IS ' + @TOTAL_MONEY + ' INSTALLMET AMOUNT IS ' + @TOTAL_MONEY/@R_INSTALLMENT_NUMBER + ' @INTEREST IS '+ @INTEREST + ' DUE DATE IS '+ (SELECT DAY(@START_DATE)) + '/' + (@SMOUNT) + '/' +(@SYEAR)
SELECT @SMOUNT = @SMOUNT + @INSTALLMENT_NUMBER-1
END
END
GO