Code
/////////////another method!!
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
/////////////another method!!
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