title: How do Recursive CTEs work in SQL Server?
body: <p>Can anyone help me understand how this recursive CTE works?</p>
  
  <pre><code>WITH
  RECURSIVECTE (EMPID, FULLNAME, MANAGERID, [ORGLEVEL]) AS
      (SELECT EMPID,
              FULLNAME,
              MANAGERID,
              1
       FROM RECURSIVETBL
       WHERE MANAGERID IS NULL
       UNION ALL
       SELECT A.EMPID,
              A.FULLNAME,
              A.MANAGERID,
              B.[ORGLEVEL] + 1
       FROM RECURSIVETBL A
            JOIN RECURSIVECTE B ON A.MANAGERID = B.EMPID)
  SELECT *
  FROM RECURSIVECTE;
  </code></pre>