I have the following PMT function:
<code>create function dbo.PMT
(
@rate float,
@periods numeric(20,7),
@principal numeric(20,2)
)
returns numeric (38,9)
as
begin
declare @pmt numeric (38,9)
declare @WK_periods float,
@WK_principal float,
@wk_One float,
@WK_power float
select @WK_periods = @periods,
@WK_principal = @principal,
@WK_One = 1
select @pmt =
round(
( @WK_principal * (@rate*power(@WK_One+@rate,@WK_periods)))
/ (power(@WK_One+@rate,@WK_periods)-@WK_One)
,9)
return @pmt
end
go
</code>
<code>create function dbo.PMT
(
@rate float,
@periods numeric(20,7),
@principal numeric(20,2)
)
returns numeric (38,9)
as
begin
declare @pmt numeric (38,9)
declare @WK_periods float,
@WK_principal float,
@wk_One float,
@WK_power float
select @WK_periods = @periods,
@WK_principal = @principal,
@WK_One = 1
select @pmt =
round(
( @WK_principal * (@rate*power(@WK_One+@rate,@WK_periods)))
/ (power(@WK_One+@rate,@WK_periods)-@WK_One)
,9)
return @pmt
end
go
</code>
create function dbo.PMT
(
@rate float,
@periods numeric(20,7),
@principal numeric(20,2)
)
returns numeric (38,9)
as
begin
declare @pmt numeric (38,9)
declare @WK_periods float,
@WK_principal float,
@wk_One float,
@WK_power float
select @WK_periods = @periods,
@WK_principal = @principal,
@WK_One = 1
select @pmt =
round(
( @WK_principal * (@rate*power(@WK_One+@rate,@WK_periods)))
/ (power(@WK_One+@rate,@WK_periods)-@WK_One)
,9)
return @pmt
end
go
and called with the following parameters:
<code>SELECT dbo.PMT(0.006313333, 251.1762480, 1814647.77)
</code>
<code>SELECT dbo.PMT(0.006313333, 251.1762480, 1814647.77)
</code>
SELECT dbo.PMT(0.006313333, 251.1762480, 1814647.77)
the result is 14425.46 while excel is producing 14334.96. Though, I noticed that excel user added 2 extra parameters, which make it different from SQL result. So, in excel, the PMT function is called as =PMT(0.006313333, 251.1762480, 1814647.77, 0, 1). I could add those 2 parameters but don’t know what to do with them in the function as I don’t understand their implementation.
I need help to make SQL server produce same result as Excel.