Skip to content

Instantly share code, notes, and snippets.

@Azsaturndx
Created February 18, 2020 23:49
Show Gist options
  • Save Azsaturndx/a9334733e4459a668bc39294d3368bcb to your computer and use it in GitHub Desktop.
Save Azsaturndx/a9334733e4459a668bc39294d3368bcb to your computer and use it in GitHub Desktop.
PPMT Function (Principal Payment) - SQL Server
/**
* Principal Payment
* (SQL Server)
* AzsaturnDx (2020) - No copyright at all
*
* Returns the payment on the principal for a given period for an investment based on periodic, constant payments and a constant interest rate.
*
* @Rate FLOAT - Required. The interest rate per period.
* @Period INT - Required. Specifies the period and must be in the range 1 to nper.
* @Periods INT - Required. The total number of payment periods in an annuity.
* @Present FLOAT - Required. The present value — the total amount that a series of future payments is worth now.
* @Future FLOAT - Optional. The future value, or a cash balance you want to attain after the last payment is made. If don't needed pass 0 as value
* @Type - Optional. The number 0 or 1 and indicates when payments are due.
* @return FLOAT Payment on the principal for a given period
*
* @Example
* SELECT dbo.PPMT(0.4,12,24,0,20000,0)
*
* REQUIRES: dbo.IPMT
* Required functions are available @: https://gist.github.com/Azsaturndx/8ce3e47e2d3210a65fc83b09ac32da5f
*/
CREATE FUNCTION [dbo].[PPMT]
(@Rate Float
,@Period INT
,@Periods INT
,@Present Float
,@Future Float
,@Type INT)
RETURNS Float
BEGIN
RETURN dbo.PMT(@Rate,@Periods,@Present,@Future,@Type) - dbo.IPMT(@Rate,@Period,@Periods,@Present,@Future,@Type)
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment