Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 237987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:28:10+00:00 2026-05-11T20:28:10+00:00

How can I get the functionality of CONNECT BY PRIOR of Oracle in SQL

  • 0

How can I get the functionality of CONNECT BY PRIOR of Oracle in SQL Server 2000/2005/2008?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:28:11+00:00Added an answer on May 11, 2026 at 8:28 pm

    The SQL standard way to implement recursive queries, as implemented e.g. by IBM DB2 and SQL Server, is the WITH clause. See this article for one example of translating a CONNECT BY into a WITH (technically a recursive CTE) — the example is for DB2 but I believe it will work on SQL Server as well.

    Edit: apparently the original querant requires a specific example, here’s one from the IBM site whose URL I already gave. Given a table:

    CREATE TABLE emp(empid  INTEGER NOT NULL PRIMARY KEY,
                     name   VARCHAR(10),
                     salary DECIMAL(9, 2),
                     mgrid  INTEGER);
    

    where mgrid references an employee’s manager’s empid, the task is, get the names of everybody who reports directly or indirectly to Joan. In Oracle, that’s a simple CONNECT:

    SELECT name 
      FROM emp
      START WITH name = 'Joan'
      CONNECT BY PRIOR empid = mgrid
    

    In SQL Server, IBM DB2, or PostgreSQL 8.4 (as well as in the SQL standard, for what that’s worth;-), the perfectly equivalent solution is instead a recursive query (more complex syntax, but, actually, even more power and flexibility):

    WITH n(empid, name) AS 
       (SELECT empid, name 
        FROM emp
        WHERE name = 'Joan'
            UNION ALL
        SELECT nplus1.empid, nplus1.name 
        FROM emp as nplus1, n
        WHERE n.empid = nplus1.mgrid)
    SELECT name FROM n
    

    Oracle’s START WITH clause becomes the first nested SELECT, the base case of the recursion, to be UNIONed with the recursive part which is just another SELECT.

    SQL Server’s specific flavor of WITH is of course documented on MSDN, which also gives guidelines and limitations for using this keyword, as well as several examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add email functionality to my app. I can get the
Project : ASP.NET 3.5 Server : SQL Server 2008 One of the page in
Can I use a SQL Server Express database as my local database for an
How can I get functionality equivalent to that of range.startOffset in Internet Explorer 8
I'm trying to get Facebook Connect functionality working in my iPhone app. I'm wondering
Can get all triples with value null in specific field? All people with date_of_birth
You can get underground processes by ps ux I am searching a way to
You can get a list of databases using PRAGMA database_list or a list of
I can get the current selected row in this way: private void DataGridView1_CellContentClick(object sender,
I can get the the first row in a ListView item in .NET 3.5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.