detecting cycles in a hierarchy using t-sql

  • If your query does not require to check multi-level circular loops you can do this:

    SELECT

    t1.*

    FROM #Tree t1

    JOIN #Tree t2 ON t1.child = t2.parent AND t1.parent = t2.child

    ORDER BY child

Viewing post 1 (of 2 total)

You must be logged in to reply to this topic. Login to reply