Microsoft SQL Server 2005 Best Practices

How to calculate the present value and future value of money?

 

Execute the following script in Query Editor to create 2 UDF-s for the money calculations:

USE AdventureWorks;

CREATE FUNCTION fnPresentValue (
@FutureValue Money,
@InterestRatePercent decimal,
@Years int )
RETURNS Money
AS
BEGIN
DECLARE @Value money

SELECT @Value = @FutureValue *(1/Power((1+@InterestRatePercent/100.0),@Years))

RETURN @Value
END
GO

-- SELECT dbo.fnPresentValue (500000, 5, 10)

CREATE FUNCTION fnFutureValue (
@PresentValue Money,
@InterestRatePercent decimal,
@Years int )
RETURNS Money
AS
BEGIN
DECLARE @Value money

SELECT @Value = @PresentValue * Power((1+@InterestRatePercent/100.0),@Years)

RETURN @Value
END
GO

-- SELECT dbo.fnFutureValue (1000000, 5, 10)


 

The Best SQL Server 2005 Training in the World
 
 
SQLUSA.com Home Page