?
Solved

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

Posted on 2006-06-08
1
Medium Priority
?
876 Views
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;

EMPLOYEE_ID LAST_NAME                 MANAGER_ID      LEVEL
----------- ------------------------- ---------- ---------- -------------
        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?
0
Comment
Question by:keenmar
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 750 total points
ID: 16859345
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

831 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