SQL Server ODDFPMTSCHED Function
Updated 2023-10-06 21:42:47.807000
Description
Use the table-valued function ODDFPMTSCHED to generate an amortization schedule for an annuity where the first period is either longer or shorter than all the other periods.
Syntax
SELECT * FROM [wct].[ODDFPMTSCHED](
<@Rate, float,>
,<@Nper, int,>
,<@PV, float,>
,<@FV, float,>
,<@FirstPeriod, float,>)
Arguments
@Rate
the periodic interest rate. @Rate is an expression of type float or of a type that can be implicitly converted to float.
@Nper
the number of annuity payments. @Nper is an expression of type int or of a type that can be implicitly converted to int.
@PV
the present value of the annuity. @PV is an expression of type float or of a type that can be implicitly converted to float.
@FV
the future value as at the end of the annuity. @FV is an expression of type float or of a type that can be implicitly converted to float.
@FirstPeriod
the length of the first period. @FirstPeriod is an expression of type float or of a type that can be implicitly converted to float.
Return Type
table
| colName | colDatatype | colDesc |
|---|---|---|
| num_pmt | int | Payment number |
| amt_prin_init | float | Initial principal amount; amt_prin_end from the previous row |
| amt_int_pay | float | Interest portion of the periodic payment |
| amt_prin_pay | float | Principal portion of the periodic payment |
| amt_prin_end | float | Ending principal amount; amt_prin_init – amt_prin_pay |
Remarks
If @Rate <= -1 then no rows are returned.
If @Nper < 1 then no rows are returned.
If @FirstPeriod <= 0 then no rows are returned.
If @Nper is NULL then @Nper = 1.
If @Rate is NULL then @Rate = 0.
If @PV is NULL then @PV = 0.
If @FV is NULL then @FV = 0.
If @FirstPeriod is NULL then @FirstPeriod = 1.
amt_prin_pay for the final period includes @FV so that the amt_prin_end for the final period is zero.
ODDFPMTSCHED uses the same conventions for the sign of the inputs and the results as Excel and Google spreadsheets; generally @PV and @FV should have opposite signs and the periodic interest and principal payments will have the opposite sign of @PV.
Examples
Generate a payment schedule for an annuity assuming a periodic rate of 0.5%, with 36 periodic payments. The price of the annuity is 11,500 and there is no cash value at the end of the annuity. The first period is 1 and 5/6th longer than the other periods.
SELECT *
FROM wct.ODDFPMTSCHED( .005, --@Rate
36, --@Nper
-11500, --@PV
0, --@FV
1 + 5 / 6e+00 --@FirstPeriod
);
This produces the following result.
| num_pmt | amt_prin_init | amt_int_pay | amt_prin_pay | amt_prin_end |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 11500 |
| 1 | 11500 | 105.416666666668 | 245.886079534899 | 11254.1139204651 |
| 2 | 11254.1139204651 | 56.2705696023263 | 295.032176599241 | 10959.0817438659 |
| 3 | 10959.0817438659 | 54.795408719338 | 296.50733748223 | 10662.5744063836 |
| 4 | 10662.5744063836 | 53.3128720319278 | 297.98987416964 | 10364.584532214 |
| 5 | 10364.584532214 | 51.8229226610788 | 299.479823540489 | 10065.1047086735 |
| 6 | 10065.1047086735 | 50.3255235433721 | 300.977222658195 | 9764.12748601531 |
| 7 | 9764.12748601531 | 48.8206374300848 | 302.482108771483 | 9461.64537724382 |
| 8 | 9461.64537724382 | 47.3082268862167 | 303.994519315351 | 9157.65085792847 |
| 9 | 9157.65085792847 | 45.7882542896573 | 305.51449191191 | 8852.13636601656 |
| 10 | 8852.13636601656 | 44.2606818300924 | 307.042064371475 | 8545.09430164509 |
| 11 | 8545.09430164509 | 42.7254715082222 | 308.577274693345 | 8236.51702695174 |
| 12 | 8236.51702695174 | 41.1825851347699 | 310.120161066798 | 7926.39686588494 |
| 13 | 7926.39686588494 | 39.6319843294318 | 311.670761872136 | 7614.72610401281 |
| 14 | 7614.72610401281 | 38.0736305200658 | 313.229115681502 | 7301.49698833131 |
| 15 | 7301.49698833131 | 36.5074849416674 | 314.7952612599 | 6986.70172707141 |
| 16 | 6986.70172707141 | 34.9335086353599 | 316.369237566208 | 6670.3324895052 |
| 17 | 6670.3324895052 | 33.3516624475337 | 317.951083754034 | 6352.38140575117 |
| 18 | 6352.38140575117 | 31.7619070287606 | 319.540839172807 | 6032.84056657836 |
| 19 | 6032.84056657836 | 30.164202832902 | 321.138543368666 | 5711.70202320969 |
| 20 | 5711.70202320969 | 28.5585101160618 | 322.744236085506 | 5388.95778712419 |
| 21 | 5388.95778712419 | 26.9447889356293 | 324.357957265938 | 5064.59982985825 |
| 22 | 5064.59982985825 | 25.3229991492922 | 325.979747052275 | 4738.62008280597 |
| 23 | 4738.62008280597 | 23.6931004140429 | 327.609645787525 | 4411.01043701845 |
| 24 | 4411.01043701845 | 22.0550521850978 | 329.24769401647 | 4081.76274300198 |
| 25 | 4081.76274300198 | 20.4088137150197 | 330.893932486548 | 3750.86881051543 |
| 26 | 3750.86881051543 | 18.7543440525824 | 332.548402148985 | 3418.32040836645 |
| 27 | 3418.32040836645 | 17.0916020418299 | 334.211144159738 | 3084.10926420671 |
| 28 | 3084.10926420671 | 15.4205463210515 | 335.882199880516 | 2748.22706432619 |
| 29 | 2748.22706432619 | 13.7411353216371 | 337.56161087993 | 2410.66545344626 |
| 30 | 2410.66545344626 | 12.0533272672383 | 339.249418934329 | 2071.41603451193 |
| 31 | 2071.41603451193 | 10.3570801725564 | 340.945666029011 | 1730.47036848292 |
| 32 | 1730.47036848292 | 8.65235184242761 | 342.65039435914 | 1387.81997412378 |
| 33 | 1387.81997412378 | 6.93909987062329 | 344.363646330944 | 1043.45632779284 |
| 34 | 1043.45632779284 | 5.21728163897058 | 346.085464562597 | 697.370863230241 |
| 35 | 697.370863230241 | 3.48685431616252 | 347.815891885405 | 349.554971344836 |
| 36 | 349.554971344836 | 1.74777485673167 | 349.554971344836 | 0 |
In this example we generate a payment schedule for an annuity assuming a periodic rate of 0.5%, with 180 periodic payments. The price of the annuity is 250,000 and there is a 50,000 cash value at the end of the annuity. The first period is one-half as long as the other periods. We will return the last 24 rows.
SELECT *
FROM
(
SELECT TOP 24
*
FROM wct.ODDFPMTSCHED( .005, --@Rate
180, --@Nper
-250000, --@PV
50000, --@FV
0.5 --@FirstPeriod
)
ORDER BY num_pmt DESC
) n
ORDER BY 1 ASC;
This produces the following result.
| num_pmt | amt_prin_init | amt_int_pay | amt_prin_pay | amt_prin_end |
|---|---|---|---|---|
| 157 | 87961.2505481276 | 439.806252740677 | 1492.65953751018 | 86468.5910106174 |
| 158 | 86468.5910106174 | 432.34295505309 | 1500.12283519776 | 84968.4681754197 |
| 159 | 84968.4681754197 | 424.842340877153 | 1507.6234493737 | 83460.844726046 |
| 160 | 83460.844726046 | 417.304223630247 | 1515.16156662061 | 81945.6831594254 |
| 161 | 81945.6831594254 | 409.728415797149 | 1522.7373744537 | 80422.9457849717 |
| 162 | 80422.9457849717 | 402.114728924895 | 1530.35106132596 | 78892.5947236457 |
| 163 | 78892.5947236457 | 394.462973618259 | 1538.00281663259 | 77354.5919070131 |
| 164 | 77354.5919070131 | 386.772959535145 | 1545.69283071571 | 75808.8990762974 |
| 165 | 75808.8990762974 | 379.044495381521 | 1553.42129486933 | 74255.4777814281 |
| 166 | 74255.4777814281 | 371.277388907144 | 1561.18840134371 | 72694.2893800844 |
| 167 | 72694.2893800844 | 363.471446900487 | 1568.99434335036 | 71125.295036734 |
| 168 | 71125.295036734 | 355.626475183705 | 1576.83931506715 | 69548.4557216669 |
| 169 | 69548.4557216669 | 347.742278608367 | 1584.72351164249 | 67963.7322100244 |
| 170 | 67963.7322100244 | 339.818661050162 | 1592.64712920069 | 66371.0850808237 |
| 171 | 66371.0850808237 | 331.855425404098 | 1600.61036484675 | 64770.4747159769 |
| 172 | 64770.4747159769 | 323.852373579972 | 1608.61341667088 | 63161.8612993061 |
| 173 | 63161.8612993061 | 315.809306496562 | 1616.65648375429 | 61545.2048155518 |
| 174 | 61545.2048155518 | 307.726024077795 | 1624.73976617306 | 59920.4650493787 |
| 175 | 59920.4650493787 | 299.602325246877 | 1632.86346500397 | 58287.6015843747 |
| 176 | 58287.6015843747 | 291.438007921931 | 1641.02778232892 | 56646.5738020458 |
| 177 | 56646.5738020458 | 283.232869010248 | 1649.2329212406 | 54997.3408808052 |
| 178 | 54997.3408808052 | 274.986704404055 | 1657.4790858468 | 53339.8617949584 |
| 179 | 53339.8617949584 | 266.699308974847 | 1665.766481276 | 51674.0953136824 |
| 180 | 51674.0953136824 | 258.370476568449 | 51674.0953136824 | 0 |
In this example we c alculate the weekly payment for an automobile lease with a term of 3 years and an annual interest rate of 25%. The amount to be financed is 11,000 and the residual value at the end of the lease is 3,500. The first payment is due 2014-11-25 and we will return the first 52 payments.
SELECT TOP 53
*
FROM wct.ODDFPMTSCHED( .25 * 7 / 365e+00,
--@Rate
156,
--@Nper
-11000, --@PV
3500, --@FV
DATEDIFF(d, '2014-11-13', '2014-11-25') / 7e+00
--@FirstPeriod
)
ORDER BY num_pmt ASC;
This produces the following result.
| num_pmt | amt_prin_init | amt_int_pay | amt_prin_pay | amt_prin_end |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 11000 |
| 1 | 11000 | 90.4109589041082 | -4.90130154744293 | 11004.9013015474 |
| 2 | 11004.9013015474 | 52.76322541838 | 32.7464319382852 | 10972.1548696092 |
| 3 | 10972.1548696092 | 52.6062219775786 | 32.9034353790867 | 10939.2514342301 |
| 4 | 10939.2514342301 | 52.4484657805561 | 33.0611915761092 | 10906.190242654 |
| 5 | 10906.190242654 | 52.2899532182028 | 33.2197041384625 | 10872.9705385155 |
| 6 | 10872.9705385155 | 52.1306806641178 | 33.3789766925474 | 10839.591561823 |
| 7 | 10839.591561823 | 51.9706444744925 | 33.5390128821728 | 10806.0525489408 |
| 8 | 10806.0525489408 | 51.8098409880741 | 33.6998163685912 | 10772.3527325722 |
| 9 | 10772.3527325722 | 51.6482665260292 | 33.8613908306361 | 10738.4913417416 |
| 10 | 10738.4913417416 | 51.4859173919131 | 34.0237399647522 | 10704.4676017768 |
| 11 | 10704.4676017768 | 51.3227898715332 | 34.1868674851321 | 10670.2807342917 |
| 12 | 10670.2807342917 | 51.1588802329052 | 34.3507771237601 | 10635.9299571679 |
| 13 | 10635.9299571679 | 50.994184726148 | 34.5154726305173 | 10601.4144845374 |
| 14 | 10601.4144845374 | 50.8286995833997 | 34.6809577732656 | 10566.7335267641 |
| 15 | 10566.7335267641 | 50.662421018732 | 34.8472363379333 | 10531.8862904262 |
| 16 | 10531.8862904262 | 50.4953452280707 | 35.0143121285946 | 10496.8719782976 |
| 17 | 10496.8719782976 | 50.3274683890968 | 35.1821889675684 | 10461.68978933 |
| 18 | 10461.68978933 | 50.1587866611726 | 35.3508706954926 | 10426.3389186345 |
| 19 | 10426.3389186345 | 49.9892961852357 | 35.5203611714296 | 10390.8185574631 |
| 20 | 10390.8185574631 | 49.8189930837262 | 35.6906642729391 | 10355.1278931902 |
| 21 | 10355.1278931902 | 49.6478734604998 | 35.8617838961654 | 10319.266109294 |
| 22 | 10319.266109294 | 49.4759334007259 | 36.0337239559394 | 10283.2323853381 |
| 23 | 10283.2323853381 | 49.3031689708032 | 36.206488385862 | 10247.0258969522 |
| 24 | 10247.0258969522 | 49.1295762182609 | 36.3800811384044 | 10210.6458158138 |
| 25 | 10210.6458158138 | 48.9551511717118 | 36.5545061849534 | 10174.0913096288 |
| 26 | 10174.0913096288 | 48.7798898406846 | 36.7297675159807 | 10137.3615421129 |
| 27 | 10137.3615421129 | 48.6037882156098 | 36.9058691410555 | 10100.4556729718 |
| 28 | 10100.4556729718 | 48.4268422676751 | 37.0828150889902 | 10063.3728578828 |
| 29 | 10063.3728578828 | 48.2490479487524 | 37.2606094079129 | 10026.1122484749 |
| 30 | 10026.1122484749 | 48.0704011913195 | 37.4392561653458 | 9988.67299230956 |
| 31 | 9988.67299230956 | 47.8908979083345 | 37.6187594483308 | 9951.05423286123 |
| 32 | 9951.05423286123 | 47.7105339931705 | 37.7991233634948 | 9913.25510949773 |
| 33 | 9913.25510949773 | 47.5293053195101 | 37.9803520371552 | 9875.27475746058 |
| 34 | 9875.27475746058 | 47.3472077412489 | 38.1624496154163 | 9837.11230784516 |
| 35 | 9837.11230784516 | 47.1642370924101 | 38.3454202642552 | 9798.7668875809 |
| 36 | 9798.7668875809 | 46.9803891870315 | 38.5292681696337 | 9760.23761941127 |
| 37 | 9760.23761941127 | 46.7956598190931 | 38.7139975375721 | 9721.5236218737 |
| 38 | 9721.5236218737 | 46.6100447624095 | 38.8996125942558 | 9682.62400927944 |
| 39 | 9682.62400927944 | 46.4235397705188 | 39.0861175861464 | 9643.5378916933 |
| 40 | 9643.5378916933 | 46.2361405766106 | 39.2735167800547 | 9604.26437491324 |
| 41 | 9604.26437491324 | 46.0478428934212 | 39.4618144632441 | 9564.80256045 |
| 42 | 9564.80256045 | 45.8586424131181 | 39.6510149435471 | 9525.15154550645 |
| 43 | 9525.15154550645 | 45.6685348072233 | 39.8411225494419 | 9485.31042295701 |
| 44 | 9485.31042295701 | 45.4775157265058 | 40.0321416301595 | 9445.27828132685 |
| 45 | 9445.27828132685 | 45.2855808008836 | 40.2240765557817 | 9405.05420477107 |
| 46 | 9405.05420477107 | 45.0927256393125 | 40.4169317173528 | 9364.63727305372 |
| 47 | 9364.63727305372 | 44.8989458297101 | 40.6107115269551 | 9324.02656152676 |
| 48 | 9324.02656152676 | 44.7042369388264 | 40.8054204178388 | 9283.22114110892 |
| 49 | 9283.22114110892 | 44.5085945121673 | 41.0010628444979 | 9242.22007826442 |
| 50 | 9242.22007826442 | 44.3120140738711 | 41.1976432827942 | 9201.02243498163 |
| 51 | 9201.02243498163 | 44.1144911266247 | 41.3951662300406 | 9159.62726875159 |
| 52 | 9159.62726875159 | 43.916021151551 | 41.5936362051143 | 9118.03363254647 |
See Also
ODDFIPMT - Interest portion of a periodic payment for an annuity with an odd first period
ODDFPPMT - Principal portion of a periodic payment for an annuity with an odd first period
ODDFPV - Present Value of an annuity with an odd first period
PMTSCHED - Calculate an amortization schedule for a loan with no odd periods.