asdsds

0

Please login or register to vote for this query.

(click on this box to dismiss)

Signal Processing Meta

Q&A about the site for practitioners of the art and science of signal, image and video processing

DECLARE @DataSource TABLE
(
    [c] TINYINT
   ,[p] TINYINT
);

INSERT INTO @DataSource ([c], [p])
VALUES (1,0)
      ,(3, 1)
      ,(2, 3)
      ,(5,1)
      ,(7, 2)
      ,(40, 0)
      ,(2, 40);

WITH DataSource ([c], [p], [level], [rank])AS
(
    SELECT [c]
          ,[p]
          ,CAST('/' AS VARCHAR(24))
          ,ROW_NUMBER() OVER (ORDER BY [c] ASC)
    FROM  @DataSource
    WHERE [p] = 0
    UNION ALL
    SELECT DS.[c]
          ,DS.[p]
          ,CAST(DS1.[level] + CAST(DS.[c] AS VARCHAR(3)) + '/' AS VARCHAR(24))
          ,DS1.[rank]
    FROM  @DataSource DS
    INNER JOIN DataSource DS1
        ON  DS1.[c] = DS.[p]
)
SELECT [c]
      ,[p]
FROM DataSource
ORDER BY [Rank]
        ,CAST([level] AS hierarchyid);

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results