打个比方,在SQL中要求10!怎么求?或者更大的数字,比如100!又怎么求?
望高手帮助,提供代码者更好!先谢谢了!
create function jc(@A int)
returns bigint as
begin
declare @R bigint,@I int
set @R=1
set @I=1
while @I<=@A
begin
set @R=@R*@I
set @I=@I+1
end
return @R
end
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2018-02-27
建议作一个自定义函数,如下:
CREATE FUNCTION [fn] (@p1 bigint )
RETURNS bigint AS
BEGIN
declare @s bigint
declare @i bigint
set @s=1
set @i=2
while @i<=@p1
begin
set @s=@s*@i
set @i=@i+1
end
return @s
END
经测试通过了。
在使用sql语时,作为一个函数引用就可以了。如
可: select fn(10)本回答被网友采纳
CREATE FUNCTION [fn] (@p1 bigint )
RETURNS bigint AS
BEGIN
declare @s bigint
declare @i bigint
set @s=1
set @i=2
while @i<=@p1
begin
set @s=@s*@i
set @i=@i+1
end
return @s
END
经测试通过了。
在使用sql语时,作为一个函数引用就可以了。如
可: select fn(10)本回答被网友采纳