Anyone know what this will return?
create function RecursiveTest(@V int)
returns @t table (i int)
as
begin
set @v = @v - 1
if @v<>0
insert into @t
select @v union
select * from dbo.RecursiveTest(@v)
else
insert into @t values (0)
return
end
select * from dbo.RecursiveTest(10)
Try it out!
Unfortunately, the argument must be less than or equal to 32 due to the number of levels of recursion SQL can handle. It's probably not very efficient, either. But, it's pretty cool!