Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to calculate compound interest

Author  Topic 

suki_66
Starting Member

12 Posts

Posted - 2010-03-29 : 15:31:40
how would you write this formula in sql
This is what i have
@FinalAmount = (@P * (1 + dbo.[IntRate](@N))^@N)

This is the error
Msg 402, Level 16, State 1, Procedure FinalAmount, Line 7
The data types decimal and int are incompatible in the '^' operator.

What I am trying to do is calculate the compound interest

david.wendelken
Starting Member

2 Posts

Posted - 2010-03-30 : 13:32:10
What are the data types for the various variables in your formula?

Don't understand what you are trying to do with this portion of the formula:

dbo.[IntRate](@N)

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-30 : 13:42:59
seems like return type of udf dbo.[IntRate] is decimal which causes this error

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

suki_66
Starting Member

12 Posts

Posted - 2010-03-30 : 16:29:42
I figured it out - the correct formula would be
@FinalAmount=@P*POWER(@N,(1+dbo.Rate(@N))
Go to Top of Page
   

- Advertisement -