SQL Server FACTORIALPOWER Function
Updated 2024-03-07 21:40:49.020000
Description
Use the SQL Server scalar function FACTORIALPOWER to calculate the step-h factorial power x(n,h).
x^{(n,h)}=x(x-h)(x-2h)\dots(x-(n-1)h)
Syntax
SELECT [westclintech].[wct].[FACTORIALPOWER] (
<@x, int,>
,<@n, int,>
,<@h, int,>)
Arguments
@x
Number of interest.
@n
Number of steps.
@h
Step-size.
Return Type
float
Remarks
If h > 0 then the falling factorial is returned.
If h < 0 then the rising factorial is returned.
If x, h or n is NULL, then an error is returned.
Examples
Example #1
SELECT n.h,
wct.FACTORIALPOWER(25, 8, n.h) as FactorialPower
FROM
(
VALUES
(-3),
(-2),
(-1),
(0),
(1),
(2),
(3)
) n (h);
This produces the following result.
| h | FactorialPower |
|---|---|
| -3 | 2159865232000 |
| -2 | 1011373988625 |
| -1 | 424097856000 |
| 0 | 152587890625 |
| 1 | 43609104000 |
| 2 | 8365982625 |
| 3 | 608608000 |
See Also
FACTLN - natural logarithm of a factorial