This is a way to do it using recursive common table expressions. If you will have rows with more than 100 tokens, add an OPTION (MAXRECURSION 500) or whatever the number is at the end of the query.;WITH cte(Lvl,ID,PrimaryBranch) AS( SELECT 1,Id, STUFF(PrimaryBranch, CHARINDEX('>', PrimaryBranch, 1), LEN(PrimaryBranch), '') FROM MyTest UNION ALL SELECT Lvl+1, t.Id, STUFF(t.PrimaryBranch, CHARINDEX('>', t.PrimaryBranch, LEN(c.PrimaryBranch) + 2), LEN(t.PrimaryBranch), '') FROM cte c INNER JOIN MyTest t ON t.Id = c.Id WHERE CHARINDEX('>', t.PrimaryBranch, LEN(c.PrimaryBranch) + 1) > 0) SELECT *FROM cte WHERE PrimaryBranch IS NOT NULLORDER BY Id,Lvl Desc