Hi,I need the help on forming parent/child hiearchy in T-sql statement,I will be giving input as Declare @parentid intset @parentid=50
DECLARE @Categories TABLE ( ParentID INT, ParentName VARCHAR(20), ChildID INT ) INSERT INTO @Categories(ParentID, ParentName, ChildID) SELECT 50,'Dept A', 501 UNION ALL SELECT 50,'Dept B', 502 UNION ALL SELECT 50,'Dept C', 503 UNION ALL SELECT 50,'Dept D', 504 UNION ALL SELECT 50,'Dept E', 505 UNION ALL SELECT 50,'Dept F', 506 UNION ALL select 501 ,'Dept G',810 UNION ALL select 501 ,'Dept H',820 UNION ALL select 810,'Dept K',1000 select 810 ,'Dept I',2000 UNION ALL
so all the child under parent (ie) 50 should get displayed.output should be:ParentID ParentName ChildID50 Dept A 50150 Dept B 50250 Dept C 50350 Dept D 50450 Dept E 50550 Dept F 506501 Dept G 810501 Dept H 820810 Dept K 1000810 Dept I 2000