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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:06:22+00:00 2026-06-07T14:06:22+00:00

Why this does not give any records in sql server 2008? ;with pricedCategories as

  • 0

Why this does not give any records in sql server 2008?

;with pricedCategories as
(
    select * from Product.Category where CategoryID not in
    (select Parent_CategoryID from Product.Category)
)
select * from pricedCategories
  • 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-07T14:06:23+00:00Added an answer on June 7, 2026 at 2:06 pm

    It seems that your query doesn’t return values when there are NULL values in subquery inside CTE (if I replace NULL in insert (1, NULL) with let’s say (1, 0) your query will work). If you want to get the categories that are not any other category’s parents even with NULL values, you can do it like this:

    DECLARE @Category TABLE (CategoryID INT, Parent_CategoryID INT)
    INSERT @Category VALUES 
    (1, NULL),
    (2, 1),
    (3, 1),
    (4, 2)
    
    ;WITH pricedCategories AS
    (
        SELECT * FROM @Category y WHERE NOT EXISTS 
        (SELECT Parent_CategoryID FROM @Category x 
         WHERE  x.Parent_CategoryID = y.CategoryID)
    )
    SELECT * FROM pricedCategories
    

    It is interesting to see that the following approach works the same as the approach described in your question:

    ;WITH pricedCategories AS
    (
        SELECT * FROM @Category y 
        WHERE  y.CategoryID <> ALL(SELECT DISTINCT Parent_CategoryID FROM @Category)
    )
    SELECT * FROM pricedCategories
    

    You could change your query to use the ISNULL function to replace NULL with some numeric value that is never used as CategoryID, like this:

    ;WITH pricedCategories AS
    (
        SELECT * FROM @Category WHERE CategoryID NOT IN
        (SELECT ISNULL(Parent_CategoryID, -1) FROM @Category)
    )
    SELECT * FROM pricedCategories
    

    But then the NULL value which means “nothing” would be changed to actual value of -1 which is not true and you shouldn’t use it.

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

Sidebar

Related Questions

I am using Zend_Db with the Pdo_Mysql driver. This query does not give any
It does not get registration id from GCM server the app does not give
This does not really apply to any language specifically, but if it matters I
I just found my code like this does not compile right? Is there any
This does NOT work: Sub X() Dim A As Access.Application Set A = CreateObject(Access.Application)
Ops: This does not belong to ServerFault because it focuses on Programing Architecture. I
Is it true that this does not necessarily mean the stream has been disposed
can anyone tell me why this does not work Excel.Worksheet ws_res = (Excel.Worksheet) wb.Worksheets.Add(mis,
How can I ensure that this does NOT open in a new window?? onclick=ob=this.form.table;window.open(ob.options[ob.selectedIndex].value)/>
This works: require 'csv' file = CSV.open(filename) puts file.shift This does not: require 'csv'

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.