Skip to content

Commit f376ccd

Browse files
Update 2 All Permutations While Loop.sql
1 parent 8c94eb8 commit f376ccd

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

Permutations, Combinations, Sequences and Random Numbers/SQL Scripts/2 All Permutations While Loop.sql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Last Updated: 07/05/2022
77
This script is written in SQL Server's T-SQL
88
99
10-
• Determining permutations can be performed with a recursive CTE; this solution uses a WHILE loop
11-
• This solution uses an initial numbers table (#Numbers) that must be populated
12-
• The #Permutations table is initially seeded from the #Numbers table
13-
• The #Numbers table could be eliminated and simply just seed the #Permutations table
14-
• To keep the record count manageable, a DELETE is performed on the #Permutations within the WHILE loop
15-
• Output is saved in the temporary table #Permutations
10+
• Determining permutations can be performed with a recursive CTE; this solution uses a WHILE loop
11+
• This solution uses an initial numbers table (#Numbers) that must be populated
12+
• The #Permutations table is initially seeded from the #Numbers table
13+
• The #Numbers table could be eliminated and simply just seed the #Permutations table
14+
• To keep the record count manageable, a DELETE is performed on the #Permutations within the WHILE loop
15+
• Output is saved in the temporary table #Permutations
1616
1717
**********************************************************************/
1818

@@ -31,18 +31,18 @@ DECLARE @vTotalNumbers BIGINT = 3;
3131
---------------------
3232
---------------------
3333
--Create a #Numbers table using recursion
34-
WITH cte_Factorial (Number)
34+
WITH cte_Numbers (Number)
3535
AS (
3636
SELECT 1 AS Number
3737
UNION ALL
3838
SELECT Number + 1
39-
FROM cte_Factorial
39+
FROM cte_Numbers
4040
WHERE Number < @vTotalNumbers
4141
)
4242
SELECT
4343
Number
4444
INTO #Numbers
45-
FROM cte_Factorial
45+
FROM cte_Numbers
4646
OPTION (MAXRECURSION 0);--A value of 0 means no limit to the recursion level
4747

4848
---------------------

0 commit comments

Comments
 (0)