the code CREATE FUNCTION Calculate_Monthly_Payment ( @mortage_amount BIGINT , @apr DECIMAL(18, 6) , @years INT ) RETURNS DECIMAL(18, 6) AS BEGIN /* A = P (i + i (1+i) −1 n ) where: A = Monthly Payment Amount P = Principle (Initial) Mortgage Amount i = APR / 12 = Monthly Interest Rate n = years * 12 = Total Number of Payments */ -- Calculate monthly interest rate DECLARE @i DECIMAL(18, 6) SET @i = @apr / 12 DECLARE @n INTEGER SET @n = @years * 12 RETURN (@mortage_amount *@i * POWER(1+@i,@n)) / (POWER(1+@i, @n) - 1) END isn't working it shows that ERROR: syntax error at or near "@" LINE 3: @mortage_amount BIGINT ^ SQL state: 42601 Character: 48
the code
CREATE FUNCTION Calculate_Monthly_Payment
(
@mortage_amount BIGINT
, @apr DECIMAL(18, 6)
, @years INT
)
RETURNS DECIMAL(18, 6)
AS
BEGIN
/*
A = P (i + i (1+i) −1 n )
where:
A = Monthly Payment Amount
P = Principle (Initial) Mortgage Amount
i = APR / 12 = Monthly Interest Rate
n = years * 12 = Total Number of Payments
*/
-- Calculate monthly interest rate
DECLARE @i DECIMAL(18, 6)
SET @i = @apr / 12
DECLARE @n INTEGER
SET @n = @years * 12
RETURN (@mortage_amount *@i * POWER(1+@i,@n)) / (POWER(1+@i, @n) - 1)
END
isn't working
it shows that
ERROR: syntax error at or near "@" LINE 3: @mortage_amount BIGINT ^ SQL state: 42601 Character: 48

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









