I'm trying to write an efficient recursive query. I've run across CTEs and have found a number of examples. However, every example I've found is returning the same data that is recursive where I need to return some different data.
For example, my hierarchical data is a table of Locations.
[Locations]
ID int
Title nvarchar(100)
ParentLocationID int
But the data I want to return is in a table of Activities. I want to return all activities associated with a particular location, and all "child" locations.
[Activities]
ID int
Title nvarchar(100)
LocationID int
I'm new to CTEs and can't quite see how to do this from the examples I have. Any help would be appreciated.