see this to understand the hierarchyWith Hierarchy_CTEAS(SELECT ID,Iname,CAST(lname AS varchar(8000)) AS PathFROM studentAWHERE Parent IS NULLUNION ALLSELECT s.ID,s.lname,CAST(c.Path + '/' + s.lname AS varchar(8000))FROM Hierarchy_CTE cINNER JOIN studentA sON s.Parent = c.ID)SELECT *FROM Hierarchy_CTEOPTION (MAXRECURSION 0)
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/