create function fn_test (
@num int
)
returns @r table (
r int
)
as
begin
declare @i int
declare @n int
set @i = 1
set @n = 1
while 2*@n<=@num
begin
set @n = @n * 2
set @i = @i + 1
end
insert @r values(@n)
set @n = @num - @n
if @n > 0
insert @r select r from fn_test(@n)
return;
end
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/16436858/viewspace-612022/
,如需转载,请注明出处,否则将追究法律责任。