Which is the equivalent of CONNECT BY PRIOR (from ORACLE) in SQL Server

Posted on 2006-06-08
Last Modified: 2012-06-21
The following hierarchical query uses the CONNECT BY clause to define the relationship between employees and managers:

(The following code is in ORACLE)
SELECT employee_id, last_name, manager_id, Level
   FROM employees
   CONNECT BY PRIOR employee_id = manager_id;

----------- ------------------------- ---------- ---------- -------------
        101        Kochhar                          100                  1
        108        Greenberg                      101                   2
        109        Faviet                            108                   3
        110        Chen                             108                   3
        111        Sciarra                          108                   3
        112        Urman                           108                   3
        113        Popp                             108                   3

I need to know what is the equivalent of CONNECT BY PRIOR in SQL Server, or how can I cross a hierarchy in SQL Server?
Question by:keenmar
    1 Comment
    LVL 142

    Accepted Solution

    what version of SQL Server?
      in sql 2005, you have to use the Common Table Expression (WITH CTE)
      in sql 2000, you have to develop a procedure/function to simulate it

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now