N - 1
/* select * from dbo.GetCounterTable(10) */ create function [dbo].[GetCounterTable] ( @V int ) returns @t table (N int) as begin set @v = @v - 1 if @v<>0 insert into @t select (@v) union select * from dbo.GetCounterTable(@v) else insert into @t values (0) return end
alter function [dbo].[GetCounterTable] ( @V int ) returns @t table (N int) as begin set @v = @v - 1 if @v > 30 begin ;with MyData as ( select N = a.N + b.N * 10 + c.N * 100 + d.N * 1000 from dbo.GetCounterTable(10) a ,dbo.GetCounterTable(10) b ,dbo.GetCounterTable(10) c ,dbo.GetCounterTable(10) d ) insert into @t (N) select N from MyData where N <= @v order by N end else if @v > 0 insert into @t (N) select (@v) union select * from dbo.GetCounterTable(@v) else if @v = 0 insert into @t values (0) return end
alter function [dbo].[GetCounterTable] ( @V int ) returns @t table (N int) as begin --declare @rows int --set @rows = 1000 ; with NumberList as ( select Number = 0 union all select Number + 1 from NumberList where Number < @V - 1 ) insert into @t select * from NumberList option(maxrecursion 0) return end
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.