Get all child records of a record from a self referencing table
Posted on 2013-01-02
I have a self referencing table (each record may or may not have a reference to another record within the same table) and I want to be able to get all child records for a particular record! I am looking for a script for the best way to accomplish this!
ID ParentID Name
1 NULL U.S.A.
2 1 PA
3 2 Pittsburgh
4 2 Harrisburg
So if I would pass the stored procedure the ID=1, it would retrun PA, Pittsburgh, and Harrisburg, while if I pass it the ID=2, it would only retrun Pittsburgh, and Harrisburg
Any help would be greatly appreciated!