Below SQL table is called FriendsInformation and it contains columns Name and FriendOf.
Here i want to form a query in such a way that i get the below output
select Name , { Code } as FriendPath from FriendsInformation where Name = 'Person7'
The query should fetch like above output where FriendPath column will fetch the parent ones friend till the FriendOf column is null.
suppose if we want to fetch Person7, i need to get all the hierarchies of friendship so that friendship path is identified
Whether With CTE would help or Do While loop help i am not sure about it. I just tried inner joins and CTE's but could not able to get the value , Could anyone assist on this ?

