Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Recursive CTE termination
-- Example to show that recursive CTE termination condition should -- be expressed inside the last SELECT in the CTE. -- Putting the termination condition outside the CTE is logically -- equivalent, but in practice only filters the output rather -- than terminating the recursion -- -- You can see the effects by toggling the commenting of the -- two "where cte.v" clauses and also toggling between "top(200)" -- and "top(100)" -- -- When using "top(200)" and using the outer "where cte.v < 5" then -- the result is an error: -- The statement terminated. The maximum recursion 100 has been exhausted before statement completion. with thedata as ( select top(200) row_number() over (order by (select null)) as v from sys.all_columns ), cte as ( select thedata.v from thedata where v=1 union all select thedata.v from thedata join cte on cte.v+1 = thedata.v -- where cte.v < 4 ) select * from cte where cte.v < 5
run
|
edit
|
history
|
help
0
Studiu Individual 1
Outer Apply successer cell chek and get the result
Recursos_Humanos
repert
persons
find count of employees with salary more than their managers
1D Hotel
book
Sequence object -- New Feature of 2012 sql server
Factorial