bobmcc-957585 (1/20/2010)
This is a sidebar but....I am struggling with how the CTE is referencing itself from within itself
This works but I need clarification on it. The CTE is referencing itself from within itself.
I did not realize this was possible.
Any clarification would be greatly appreciated.
;WITH mycte AS
(SELECT 100 AS seedValue
UNION ALL
SELECT seedValue + 1 FROM mycte WHERE seedValue + 1 < 200
)
select * from mycte
Hi Bob
This is a recursive CTE, which is a supported structure in TSQL
One nice use for it is to navigate a parent-child relationship of uncertain depth. MSDN has an article on it at http://msdn.microsoft.com/en-us/library/ms186243.aspx