CREATE PROCEDURE dbo.ShowHierarchy
(
@Root int,
@idList varchar(100) OUTPUT
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @IndID int, @IndName varchar(30)
SET @IndName = (SELECT ID FROM dbo.forum_industries WHERE ID = @Root)
PRINT REPLICATE('-', @@NESTLEVEL * 4) + @IndName
SET @idList = @idList + ',' + CAST(@IndName AS VARCHAR(100))
SET @IndID = (SELECT MIN(ID) FROM dbo.forum_industries WHERE ParentID = @Root)
WHILE @IndID IS NOT NULL
BEGIN
EXEC dbo.ShowHierarchy @IndID, @idList--, @finalIdList
SET @IndID = (SELECT MIN(ID) FROM dbo.forum_industries WHERE ParentID = @Root AND ID > @IndID)
END
END
|