May 15, 2013 at 6:15 am
Dear all,
I got following code in one procedure and did not get why its use and what is it for :
;WITH
L0 AS (SELECT 1 AS c UNION ALL SELECT 1),
L1 AS (SELECT 1 AS c FROM L0 A CROSS JOIN L0 B),
L2 AS (SELECT 1 AS c FROM L1 A CROSS JOIN L1 B),
L3 AS (SELECT 1 AS c FROM L2 A CROSS JOIN L2 B),
L4 AS (SELECT 1 AS c FROM L3 A CROSS JOIN L3 B),
Nums AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS i FROM L4),
FilteredNums AS (SELECT i FROM Nums WHERE i<= 400)
Please explain.
Thanks in advance 🙂
May 15, 2013 at 6:26 am
That code is a series of CTEs (Common Table Expressions) that create a virtual numbers table.
CTE's require the previous statement to be terminated by a semi-colon (;) and because this is not the habit of most SQL Server developers CTE's are often started with a semi-colon as in your example. The better method is to terminate all statements with a semi-colon as that is supposed to become mandatory in a future version of SQL Server.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
May 15, 2013 at 6:31 am
Thanks Jack. . .
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply