Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How can i select the step count of a recursive CTE ?

$
0
0

I want to select the step count of this query (which one is do fiirst and continue + 1)  from query below

;WITH EmpCTE( BomID , empid, mgrid,BomMgrId, lvl, Qty , FLG)


AS


  SELECT     BomID , empid , mgrid, 0 as BomMgrId , 0, Qty , FLG
  FROM Employees
  WHERE empid = 1

  UNION ALL

  SELECT   E.BomID , E.empid, E.MgrId, M.BomID as BomMgrId , M.lvl+1 , E.Qty , E.FLG 
  FROM Employees AS E
    JOIN EmpCTE AS M
      ON E.mgrid = M.empid
)

SELECT BomID , empid, BomMgrId as mgrid , FLG , qty , lvl FROM EmpCTE  WHERE  FLG is null 



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>