finding full path of subgroup with t-sql?
-
hi I have a table with this records(GroupId,ParentGroupId,GroupName). i want to show a group with its full path, from main parent to it self like this: red cherry: red cherry>>cherry>>fruit i write a Procedure that give me its parents names,but i want to have a prosedure that append the parents name and give me one string i want to do this for all records in that table thanx for u answers
-
hi I have a table with this records(GroupId,ParentGroupId,GroupName). i want to show a group with its full path, from main parent to it self like this: red cherry: red cherry>>cherry>>fruit i write a Procedure that give me its parents names,but i want to have a prosedure that append the parents name and give me one string i want to do this for all records in that table thanx for u answers
What you need is a common table expression[^] which is recursive processing of a table. This may not be correct as your structure seems to be rigid (you know how many level to the top) and therefor you simply do a bunch of inner joins.
Select *
From Fruit
Inner join Category on Category.CategoryID = Fruit.CategoryID
Inner Join level2.ID = Category.Level2.ID
...Never underestimate the power of human stupidity RAH