Results 1 to 3 of 3

Thread: Getting all childs recursively in query [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818

    Resolved Getting all childs recursively in query [RESOLVED]

    i have this 'manager like' table : ManagerID + Name + ParentID which it can have many descendants inside ex:

    1 + A + 0
    2 + B + 1
    3 + C + 2
    4 + D + 2
    5 + E + 1
    6 + F + 0
    7 + G + 6
    ...

    so when i want to get all childs for parent 1 it will return

    B - C - D then
    E without any childs

    any insight?

    PS: i'm using SQL SERVER 2005

    thanks,
    Last edited by erickwidya; Jan 20th, 2009 at 11:22 PM.

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818

    Re: Getting all childs recursively in query

    it can be done using Common Table Expression

    Read BOL for more information

    PS: this only valid for SQL 2005 and above

    thanks

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Getting all childs recursively in query [RESOLVED]

    This would be relevant, and for SQL Server 2000.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

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



Click Here to Expand Forum to Full Width