Results 1 to 2 of 2

Thread: sql tree list

  1. #1
    Join Date
    Sep 2003

    Unanswered: sql tree list

    i am using a table called user. it contains user code, user name, manager code. i have stored lot of informations in this table for the user. now i want to list all the users under a manager code. how to develop a query for this.

    user code user name manager code
    001 abc 001
    002 bcd 003
    003 cde 009
    004 def 011
    005 efg 003
    006 fgh 004
    007 ghi 005
    008 hij 002

    now i want to get the output like this.

    002 005
    008 007

    help me

  2. #2
    Join Date
    Jun 2003
    Provided Answers: 1
    There are a several ways to navigate a tree structure such as yours, but none that I can think of easily produce a format like:

    002 005
    008 007

    I'm not sure how you would want the results to look if a manager has more than two employees.

    The more common output formats either just list all the employees that report to a manager, either directly or indirectily, or they output a format similar to this:


    Would either of these do? If you really need to output more than one employee record per row, I think you will need to use a cursor and loop through your hierarch constructing a string for each level.

    Let me know which way you are heading on this, and I'll try to help you out.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts