Re: An SQL Teaser Question
Posted in 2001
Steve Romankiw1 wrote: > > I would like to generate an Org Chart using SQL. I am able to generate a > list when working from the root. > However, I have hit a mental block when it comes to traversing the tree from > a branch to leaf. > > For example, starting from "Corporate HQ" is easy. Simply start where > "parent is null". > How do you traverse the org chart when starting at "Div - 1"? You write a recursive stored procedure. Write a procedure that finds all children for a given parent. Then it simply calls itself using each child as a parent. > Do I need some sort of "levels" indicator? Yes. You need to know how far to indent. > Any thoughts would be appreaciated. Sorry, that's all you're getting as I don't have time to write it. If you search the archives, you may find one I did a few years ago, but I can't promise. Cheers, -- Mark. +----------------------------------------------------------+-----------+ | Mark D. Stock mailto:mdstock@mydas.freeserve.co.uk |//////// /| | http://www.informix.com http://www.informixhandbook.com |///// / //| | http://www.iiug.org +-----------------------------------+//// / ///| | |This email will self-destruct in |/// / ////| | |10 sec. If you received this email |// / /////| | |in error, sorry about the mess. |/ ////////| +----------------------+-----------------------------------+-----------+