I have a table with columns like
entityID, entityName, parentID
How can I write a query to return all the levels of parents for an entity as to return something like
childentityname, parentlevel1name, parentlevel2name, parentLevel3name and so on
I am not a SQL ninja by any means. Is this possible? If so, how?
I’m using Microsoft SQL Server DB.
A recursive CTE is what you need look here (EDIT: Only in SQL SERVER 2005+)
Something along the lines of: