Factor
Factor

Reputation: 21

SQL function to calculate simple interest

I have worked on the solution, I need some intervention to optimize the solution.

Here is my current script:

create function SI (@Principal int, @roi int , @time int)
returns int 
as 
begin 
    declare @Principal_Amt int
    --set @Principal_Amt = 10000
    set @Principal_Amt = @Principal

    declare @rate int
    --set @rate=10
    set @rate = @roi

    declare @time_period int
    --set @time_period = 5
    set @time_period = @time

    declare @Simple_Interest int
    set @Simple_Interest = @Principal_Amt * @rate * @time_period / 100

    return @Simple_Interest
end

select dbo.SI(10000, 8, 5)

Upvotes: 0

Views: 3348

Answers (1)

Ilyes
Ilyes

Reputation: 14928

It's only

create function SI(@Principal int = 0, @roi int = 0, @time int = 0)
returns int 
as 
begin 
return (@Principal * @roi * @time /100)
end

You don't need to declare those variables, since you already have them, so use them directly.

Upvotes: 3

Related Questions