select @sum=1,@count=1
label:
select @sum=@sum*@count
select @count=@count +1
if @count <=20
goto label
select @sum
这个是sql的 1到20的阶乘 count少于15可以直接定义@sum int 大于的话会算数溢出
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
declare @sum bigint,@count intselect @sum=1,@count=1
label:
select @sum=@sum*@count
select @count=@count +1
if @count <=20
goto label
select @sum
这是20阶乘 如果count少于15可以用int
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)