vpetkovic
4/23/2020 - 1:57 AM

CTL to Generate Numbers

Generate X amount of numbers

	
	DECLARE @limit INT = 1000
	;WITH
	Nbrs_3( n ) AS ( SELECT 1 UNION SELECT 0 ),
	Nbrs_2( n ) AS ( SELECT 1 FROM Nbrs_3 n1 CROSS JOIN Nbrs_3 n2 ),
	Nbrs_1( n ) AS ( SELECT 1 FROM Nbrs_2 n1 CROSS JOIN Nbrs_2 n2 ),
	Nbrs_0( n ) AS ( SELECT 1 FROM Nbrs_1 n1 CROSS JOIN Nbrs_1 n2 ),
	Nbrs ( n ) AS ( SELECT 1 FROM Nbrs_0 n1 CROSS JOIN Nbrs_0 n2 )
	INSERT INTO @tbl
	SELECT n as [Period]
		FROM ( SELECT ROW_NUMBER() OVER (ORDER BY n)
				FROM Nbrs ) D( n 
				)
		WHERE n <= @limit