I want to show categories in one line, let's give an example like this:
Category for a product iPhone 6 -> Apple -> Mobile Phones -> Electronics
I just want to show the current category of the product + a top category + the top category, so:
Electronic / ... / Apple / iPhone 6, I want to show the ... between categories that I don't want to show.
Here is my code
WITH cte AS (
SELECT a1.*
FROM dbo.viewFeatureProductCategory a1
WHERE a1.Id = 1000184
UNION ALL
SELECT a2.*
FROM dbo.viewFeatureProductCategory a2
join cte c on a2.Id = c.ParentId
) SELECT TOP 1 SUBSTRING((SELECT ' / ' + SPACE (1) + Name as 'data()' FROM cte order by ParentId for XML PATH('')), 4, 99999) from cte
and here is result of the code