我正在尝试在 ErlangC 函数中使用这个阶乘。但是我的代理数量可以达到 300 多个。有了这个,你可以获得相当大的数字。例如. _ 我的问题是如何存储和计算这些数字?本机 SQL 有没有办法。我知道我可以去 CLR 做一个外部函数。但为了简单起见,我想保留这个原生 SQL。真的想从这里到 9 点和 10 点。但是当我解决这个问题时,我会完成的。提前感谢您提供的任何帮助。
ALTER FUNCTION [dbo].[Factorial] ( @iNumber int )
RETURNS float
AS
BEGIN
Declare @i float
IF @iNumber <= 1
SET @i = 1
ELSE
SET @i = @iNumber
WHILE @iNumber > 1
BEGIN
SET @i = @i * (@iNumber - 1)
Set @iNumber = @iNumber -1
END
RETURN (@i)
END
ErlangC代码如下:
ALTER FUNCTION [AMS].[ErlangC]
(
-- Add the parameters for the function here
@m float -- Number of Agents
,@u float -- Traffic floatensity
)
RETURNS float
AS
BEGIN
--Source http://www.mitan.co.uk/erlang/elgcmath.htm Number 6
-- Return Variable
DECLARE @Prob Float -- Probability of Call not being answered immediately and having to wait.
-- Variables
Declare @Numerator Float -- Top of Equation
Declare @Denominator Float -- Bottom of Equation
Declare @Summation float -- Summation part of Denominator
Declare @k float -- increment for summation
--Calculate Numerator
SET @Numerator = Power(@u,@m)/dbo.Factorial(@m)
-- Start Summation with k starting at 0.
SET @k = 0
SET @Summation = 0
While @k < @m-1
Begin
SET @Summation = @Summation + Power(@u,@k)/dbo.Factorial(@k)
SET @k = @k +1
End
--Calculate denominator
SET @Denominator = Power(@u,@m)/dbo.Factorial(@m) + (1-@u/@m)*@Summation
SET @Prob = @Numerator/@Denominator
-- Return the result of the function
RETURN @Prob
END