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 757417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:21:36+00:00 2026-05-14T15:21:36+00:00

Based on an existing table I used CTE recursive query to come up with

  • 0

Based on an existing table I used CTE recursive query to come up with following data. But failing to apply it a level further.

Data is as below

id    name     parentid
--------------------------
1     project   0
2     structure 1
3     path_1    2
4     path_2    2
5     path_3    2
6     path_4    3
7     path_5    4
8     path_6    5

I want to recursively form full paths from the above data. Means the recursion will give the following output.

FullPaths
-------------
Project
Project\Structure
Project\Structure\Path_1
Project\Structure\Path_2
Project\Structure\Path_3
Project\Structure\Path_1\path_4
Project\Structure\Path_2\path_5
Project\Structure\Path_3\path_6

Thanks

  • 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-14T15:21:37+00:00Added an answer on May 14, 2026 at 3:21 pm

    Here’s an example CTE to do that:

    declare @t table (id int, name varchar(max), parentid int)
    
    insert into @t select 1,     'project'  , 0
    union all select 2,     'structure' , 1
    union all select 3,     'path_1'    , 2
    union all select 4,     'path_2'    , 2
    union all select 5,     'path_3'    , 2
    union all select 6,     'path_4'    , 3
    union all select 7,     'path_5'    , 4
    union all select 8,     'path_6'    , 5
    
    ; with CteAlias as (
        select id, name, parentid
        from @t t
        where t.parentid = 0
        union all
        select t.id, parent.name + '\' + t.name, t.parentid
        from @t t
        inner join CteAlias parent on t.parentid = parent.id
    )
    select * 
    from CteAlias
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see that EF can update a model based on an existing database schema.
I have an existing web app that allows users to rate items based on
I have an existing website that uses the same code base, but is deployed
I write an application based on an already existing database (postgreSQL) using JPA and
I'm going to rebuilt an existing moderate-scale web-app to be used for a supply-chain-management
I have a table with about 2,000,000 rows. I need to query one of
I am making a cookie based favorite system and need to join data from
I have an application that sends data based on user interaction (not user input).
We are running Selenium regression tests against our existing code base, and certain screens
Based on a simple test I ran, I don't think it's possible to put

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.