I have a table that shows relations between records in a sort of "parent to child" fashion. An [ID] field identifies a record and a [PARENT] field identifies that record's parent by [ID]. This creates a tree structure for the top-most parent. See the below table as an example:
[ID]     [PARENT]     [QUANTITY]
123      123          1
456      123          2
789      123          1
321      456          1
654      321          2
987      321          4
Notice how record with [ID] = '123' is the top-most record in this "tree". I need to query this table to select all tree nodes (complete records) under the top-most record, for example all of the records beneath [ID] = '123' in the tree (all records in the above sample table). Currently I am using a stored procedure to loop grabbing the children of the record with [ID] = '123', then that records children, etc. I know there must be an easier query (not a stored proc) that could dynamically adapt to this situation I just am not sure how that might work without looping to ensure all children are received. Any advice is appreciated.
 
     
    