Logo

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.

hFactorialPower
-32159865232000
-21011373988625
-1424097856000
0152587890625
143609104000
28365982625
3608608000

See Also

FACT - factorial of a number

FACTLN - natural logarithm of a factorial

GAMMA - complete gamma function

GAMMALN - natural logarithm of the complete gamma function