0
votes

I have a Location table:

Id int
MasterLocationId int
Name varchar(50)

A location can have a master location and so on. There's no specific limit to how many levels this could be.

How can I search for any locations with a certain ID, or locations where a master record has that ID, or its master record has that ID - and so on.

I'm not really sure what to even search for on Google here - perhaps this type of situation has a name and I'm not sure what it's called?

I've searched for recursive TSQL and couldn't find anything.

Is this possible?

Thanks

You couldn't find anything? That's odd, because recursive CTEs are explicitly a topic in the docs (and I can find this even if I leave out "CTE"), with the ever-popular example of an employee hierarchy. - Jeroen Mostert
Actually I did find those but I didn't realise they do what I need and didn't really understand how they work. I'll look again... - niico