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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:16:52+00:00 2026-06-02T02:16:52+00:00

I am working on a website which have pages arranged in one table with

  • 0

I am working on a website which have pages arranged in one table with Parent Child Relation. Page depth can go to any level and i want to generate BreadCrumb for the website based on the database. Sample Data and data fields as shown in the Image below.

Basic Table Structure is like
TableName Web_Pages

Table Columns
( PageID int, PageName Varchar, PageInternalLinkURL Varchar,PageInheritance int)

Example of Sample Data in the table
Example of Table Data

Example of BreadCrumb on Page
Example of BreadCrumb on Page

I want the Bread crumb for the site navigation to look similar to what is shown in the sample image below.

I tried for weeks but was not able to get it right.

I want to use it with out site map, rather i would like to create it grammatically and link the PageName field with the correct Page URL.

I want to do it so that when ever a page is added to CMS Bread crumb is created dynamically which can work with any page depth.

I worked with CTE query which is not working properly. I would appreciate if someone resolve this issue or can point to a complete working example which is similar to mine.

Testing CTE not working

SELECT * FROM pg_Pages;
WITH RecursiveTable (PageId, PageInheritance, Level)
AS
(
   --Anchor
    SELECT      tt.PageId,  tt.PageInheritance,  0 AS Level
    FROM pg_Pages AS tt
    WHERE PageInheritance = 0
    UNION ALL
    --Recursive member definition
    SELECT  tt.PageId, tt.PageInheritance, LEVEL + 1
    FROM pg_Pages AS PageId
        INNER JOIN RecursiveTable rt ON
        tt.PageInheritance = rt.PageId
)
SELECT * 
FROM RecursiveTable
  • 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-06-02T02:16:53+00:00Added an answer on June 2, 2026 at 2:16 am

    It looks like your CTE is wrong – you are almost there but the Recursive Member Definition bit looks wrong.

    Try:

    SELECT * FROM pg_Pages;
    WITH RecursiveTable (PageId, PageInheritance, Level)
    AS
    (
       --Anchor
        SELECT      tt.PageId,  tt.PageInheritance,  0 AS Level
        FROM pg_Pages AS tt
        WHERE PageInheritance = 0
        UNION ALL
        --Recursive member definition
        SELECT  tt.PageId, tt.PageInheritance, Level + 1
        FROM pg_Pages AS tt
            INNER JOIN RecursiveTable rt ON
            tt.PageInheritance = rt.PageId
    )
    SELECT * 
    FROM RecursiveTable
    --SELECT * FROM RecursiveTable WHERE Level = 0
    

    In your original attempt, your alias for pg_Pages needs to be tt (and you need to prefix PageInheritance with tt too).

    Otherwise, it looks fine.

    EDIT

    For your additional question, you can just add the additional columns:

    SELECT * FROM pg_Pages;
    WITH RecursiveTable (PageId, PageName, PageInternalLink, PageInternalLinkUrl, PageInheritance, Level)
    AS
    (
       --Anchor
        SELECT      tt.PageId,  tt.PageName, tt.PageInternalLink, tt.PageInternalLinkUrl, tt.PageInheritance,  0 AS Level
        FROM pg_Pages AS tt
        WHERE PageInheritance = 0
        UNION ALL
        --Recursive member definition
        SELECT  tt.PageId,  tt.PageName, tt.PageInternalLink, tt.PageInternalLinkUrl, tt.PageInheritance, Level + 1
        FROM pg_Pages AS tt
            INNER JOIN RecursiveTable rt ON
            tt.PageInheritance = rt.PageId
    )
    SELECT * 
    FROM RecursiveTable
    --SELECT * FROM RecursiveTable WHERE Level = 0
    

    FURTHER EDIT:

    Okay, to do what you want, you can turn the query around; provided you know the page id:

    DECLARE @PageId int
    SET @PageId = 39;
    WITH RecursiveTable (PageId, PageName, PageInternalLink, PageInternalLinkUrl, PageInheritance, Level)
    AS(
       --Anchor
        SELECT      tt.PageId,  tt.PageName, tt.PageInternalLink, tt.PageInternalLinkUrl, tt.PageInheritance,  0 AS Level
        FROM TestPage AS tt
        WHERE PageId = @PageId
        UNION ALL
       --Recursion
        SELECT tt.PageId,  tt.PageName, tt.PageInternalLink, tt.PageInternalLinkUrl, tt.PageInheritance, Level + 1
        FROM TestPage AS tt
        INNER JOIN RecursiveTable rt ON rt.PageInheritance = tt.PageId
    )
    SELECT * FROM RecursiveTable ORDER BY Level DESC
    

    What we do here is start off at the page you are on, then work backwards through the table looking for all parents. In this instance, the record with the highest level is the ultimate parent, so we order by level in descending order to reflect this.

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

Sidebar

Related Questions

i have one website which is working on templates. in the template there is
I am working on a website on which we have use parallax effect. In
I'm working on a shopping cart in a website and I have my items(which
I'm working on a website which has advert banners which link to external pages.
I am working on one real estate website which is Using RETS service to
I am working on a website in which many users can create their account
Thank you in advance for any help. I have a website which has OpenGraph
I'm working on a website which handles large amounts of data. I have got
i have a website A in which i am login and redirecting to page
I am working on a website in which the client wishes to have users

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.