Calculating financial values in SQL Server
Takeaway: Although SQL Server 2000 and 2005 do not include much in the way of financial functions, Arthur Fuller shows you how to use the present value and future value functions to calculate financial functions in SQL Server.
SQL Server 2000 and 2005 do not include much in the way of financial functions, but there are many sources for the formulas for financial calculations. In this tip, I present the present value (PV) and future value (FV) functions, both of which are scalar UDFs.
Here's the basic logic of PV: Given a value in the future and an interest rate, and the number of compounding periods, the PV calculation determines the value of said investment now. The formula is:
PV = FV [ 1 / (1 + i)n ]
Listing A demonstrates that this is not difficult to turn into a SQL Server UDF.
The converse of PV is FV; that is, given an amount of money now, an interest, and a number of compounding periods, what will your money be worth at the end?
The formula for this calculation is:
FV = PV (1 + i)n
When you translate this formula into a SQL Server function, you get the code in Listing B.
Once you have the formula in hand, it is not difficult to create the functions your application needs. For instance, if the values were stored in a table, you could pass them in as parameters to the functions.
Miss a tip?
Check out the SQL Server archive, and catch up on the most recent editions of Arthur Fuller's column.
TechRepublic's free SQL Server newsletter, delivered each Tuesday, contains hands-on tips that will help you become more adept with this powerful relational database management system. Automatically subscribe today!
Print/View all Posts Comments on this article
SponsoredWhite Papers, Webcasts, and Downloads
- Live Webcast: Energy Efficient Data Centers - Lower Costs, Greener Outcomes PC Connection
- Improving Decision Making Through Enterprise Information Management SAP
- Privileged Account Management: Recognize and mitigate UNIX/Linux security risks Quest Software
- Voice over IP Reliability: Architecture Matters ShoreTel
- The Road Ahead for Business Process Management SAP
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET

