Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION getLLTree(@ParentID int = 2000)
RETURNS @Result TABLE
(
DataID int NOT NULL,
SubType int NOT NULL,
ChildLevel int NOT NULL
)
AS
BEGIN
DECLARE @Level int
SET @Level = 0
INSERT INTO @Result SELECT DataID as DataID, SubType as SubType, @Level as ChildLevel FROM Dtree WHERE ParentID = @ParentID
WHILE @@RowCount > 0
BEGIN
IF (@Level >= 100) BREAK --if we are going 100 levels down, something must have gone wrong
SET @Level = @Level + 1
INSERT INTO @Result
SELECT DataID, Subtype, @Level FROM
Dtree WHERE ParentID IN
(SELECT DataID FROM @Result WHERE ChildLevel = @Level -1)
END
RETURN
END