Don't use recursive CTEs to generate number sequences. You can only have a maximum of 32,767 numbers, and it's less efficient than the CROSS JOIN method. The recursive method on my server executes in about 23ms; the CROSS JOIN (below) in 0ms.
WITH N7 AS (
SELECT n FROM (VALUES (1),(2),(3),(4),(5),(6),(7)) v(n)
)
, N49 AS (
SELECT N1.n
FROM N7 N1 CROSS JOIN N7 N2
)
, N2401 AS (
SELECT N1.n
FROM N49 N1 CROSS JOIN N49 N2
)
, NumberSequence(n) AS (
SELECT ROW_NUMBER() OVER (ORDER BY n)
FROM N2401
)
SELECT 0.99 + n*0.01
FROM NumberSequence
WHERE n <= 1901
John
Thanks so much for the feedback !
All of the solutions worked however after seeing John Mitchell-245523 CROSS JOIN solution and testing it for my self I am abandoning the Recursive CTE and switching over to that method.
Thanks again gentlemen!:-D
***SQL born on date Spring 2013:-)
Absolutely the right way to go, I just wanted to clarify the problem with the code presented as getting the right data type in a recursive CTE is one of the tricky things about it, and one of the many reasons I never use them.
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply