My CTE runs in an infinite loop for a specific customer and I am not able to find out why.
Here is the query:
;WITH ClassTree
AS (SELECT ID, NAME, Parent_ID
FROM TableName
WHERE ID = 1
UNION ALL
SELECT T.ID, T.NAME, T.Parent_ID
FROM TableName T WITH (NOLOCK)
JOIN ClassTree
ON Parent_ID = ClassTree.ID
)
SELECT * FROM ClassTree
ID
is joined to aParent_ID
, and somewhere in that chain theParent_ID
is joined to a sameID
. That would be the cause of the loop. – Thomas Stringer Apr 5 '12 at 12:46