T-SQL Tree Search
Select from set of nodes if they are under a parent
I have a very large tree in a MSSQL Db (80000+) records. My client has requested a quick search of the tree via a text LIKE
command. The LIKE
command returns < 500 records.
Is there some recursive command that will check the tree of each quickly to see if they are under a particular node?
Edit: I thought it was fairly clear however....
I am on SQL Server 2005.
Table Schema
- (pK) Id
- (fK) ParentId
- FirstName
- LastName
I have recursive calls that are able to go down several levels quickly. however to do the Name search I would have to poll the entire tree which can be several hundred levels deep and is not an option. I was hoping for help designing a query so I can search the entire table first for the name match and filter the records that are not part of the tree in question.