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

  • Home
  • SEARCH
  • 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 7420625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:16:15+00:00 2026-05-29T08:16:15+00:00

I have a CMS system which has a sitemap table with a parent-child relationship

  • 0

I have a CMS system which has a sitemap table with a parent-child relationship and a content table. Sometimes I don’t want to include content in queries if it’s corresponding sitemap entry or any of its parents is disabled.

The basic table structure is:

tb_Sitemap: id, parent_id, enabled

tb_Content: id, sitemap_id

So I want to be able to add something to my queries like this:

SELECT * FROM tb_Content WHERE {tb_Sitemap.enabled and any or all parents are also enabled}

I know I need to use a CTE but I am unsure about how to add these to a WHERE clause or how to go about it.

I am guessing I need do something like, but not sure how to add to a WHERE clause:

;WITH cte (enabled)
AS
(
SELECT enabled FROM tb_Content WHERE id = tb_Content.sitemap_id
UNION ALL
SELECT CASE WHEN b.enabled != 1 THEN 0 ELSE a.enabled FROM tb_Sitemap a
INNER JOIN cte b ON a.parent_id = b.id
)
SELECT enabled FROM cte

Sample data:

tb_Sitemap

  • id: 1, parent_id: null, enabled: 1
  • id: 2, parent_id: 1, enabled: 1
  • id: 3, parent_id: 2, enabled: 1
  • id: 4, parent_id: 1, enabled: 0
  • id: 5, parent_id: 4, enabled: 1
  • id: 6, parent_id: 5, enabled: 1

tbl_Content

  • sitemap_id: 3 (this would appear because sitemap_id:3 is enabled as is all of its parents)
  • sitemap_id: 6 (this will not appear because although sitemap_id:6 is enabled, one of its parents is not)
  • 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-29T08:16:16+00:00Added an answer on May 29, 2026 at 8:16 am
    -- A little test data.
    declare @tb_Sitemap as table ( id int, parent_id int null, enabled bit )
    insert into @tb_Sitemap ( id, parent_id, enabled ) values
      ( 1, NULL, 1 ), ( 2, 1, 1 ), ( 3, 2, 1 ),
      ( 4, 1, 0 ), ( 5, 4, 1 ), ( 6, 5, 1 )
    declare @tb_Content as table ( sitemap_id int )
    insert into @tb_Content ( sitemap_id ) values ( 3 ), ( 6 )
    
    -- Query the little beggars.
    ; with CTE as (
      -- Start at the root(s).
      select id, parent_id, enabled, enabled as summary_enabled
        from @tb_Sitemap
        where parent_id is NULL
      union all
      -- Add one generation at a time.
      select S.id, s.parent_id, s.enabled, cast( case when s.enabled = 1 and CTE.summary_enabled = 1 then 1 else 0 end as bit )
        from CTE inner join
          @tb_Sitemap as S on S.parent_id = CTE.id
      )
    select *, case when summary_enabled = 1 and sitemap_id is not NULL then '< winner!' else '' end as include
      from CTE left outer join
        @tb_Content as C on C.sitemap_id = CTE.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I looking for free ASP.NET based content management system (CMS) which has the following
Our in-house built CMS system has the ability to have descriptive url ( Descriptive
We have a CMS which has several thousand text/html files in it. It turns
I have an application that used another php cms system, which I am now
I have a CMS system written in ASP.NET which among other things allows users
At my current job we have a CMS system that is .NET/SQL Server based.
I have a 'template' system in my CMS rails app. Basically the whole HTML
I have a CMS with a WYSIWYG editor which produces pretty good xhtml. Based
I have a cms which stores comments against articles. These comments can be both
We have a CMS where people can upload images. We currently don't offer a

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.