I would like to use a T-SQL query (it can be recursive CTE or anything) where I could get the following output as highlighted
SQL to create sample table as follows
--drop table #hierarchy
CREATE TABLE #hierarchy
(
ID INTEGER NOT NULL PRIMARY KEY,
Value CHAR(10) NOT NULL,
);
INSERT INTO #hierarchy
VALUES (1, 'a1'), (2, 'b2'), (3, 'c3'), (4, 'd4'),
(5, 'e5'), (6, 'f6'), (7, 'g7'), (8, 'h8');
Any suggestions welcome, have tried recursive cte similar to factorial manipulation, however would appreciate inputs.
Thanks in advance.
