I have the following CTE Query
;WITH cte AS (
SELECT 0 AS lvl, id, catName, parent,
CAST(id AS VARCHAR(128)) AS Sort
FROM CategoriesMap WHERE id =2
UNION ALL
SELECT p.lvl + 1, c.id, c.catName, c.parent,
CAST(CAST(c.id AS VARCHAR) + '_' + p.Sort AS VARCHAR(128))
FROM CategoriesMap c
INNER JOIN cte p ON p.parent = c.id
)
select * from cte
The Sort(Tree) Column has output like this (for two rows)…
2
1_2
Where, 2 is a Category TVs and 1_2 means this is tree map (1: Internet Tv, 2 = Jadoo Tv)
Now can I return the Category Name with the Category Code as well?
something like
2:Jadoo Tc
1_Internet Tv: 2_Jadoo Tv
Thanks
1 Answer