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 can generate my models and schema.yml file based on an existing database. But
I'm moving an existing MySQL based application over to Cassandra. So far finding the
I see that EF can update a model based on an existing database schema.
I have existing java code and need to create Design Document based on that.
Background I have an existing extension designed to accompany a browser-based game (The extension
I have an existing web app that allows users to rate items based on
I'm looking at integrating an ESB into an existing Java/Maven web based product. Specifically,
I have no clue how i can get an existing object structure based on
I write an application based on an already existing database (postgreSQL) using JPA and
My problem is I have an existing table that I can not modify that

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.