I would think that some well-designed SQL would allow you to accomplish what you want without a recursive subroutine. See Joe Celko's writings on adjacency lists and nested sets to handle hierarchical data in relational databases. For example: Celko1,
Celko2,
Celko3.
Yikes, you erased your question. PLEASE put it back, the whole point of a site like this is so people can learn from previous examples and if you erase the question, the responses to it become meaningless.