Howto select articles with ParentId = NULL?

Posted on 2007-10-21
Last Modified: 2008-01-09
I have a stored procedure (see below) that take out all articles based on @ParentId. It works good, but some articles has ParentId = NULL in the database. When @ParentID = Null or nothing, it dont return the articles with parentId = NULL. What is wrong, how can I get the articles with ParentId = NULL?

ALTER PROCEDURE [dbo].[spGetContentsForTreeview]
    @ParentId int = null

SELECT Id, [Name]  FROM tblContent  WHERE ParentId=@ParentId
Question by:webressurs
    1 Comment
    LVL 142

    Accepted Solution

    like this:

    ALTER PROCEDURE [dbo].[spGetContentsForTreeview]
        @ParentId int = null

    SELECT Id, [Name]  FROM tblContent  WHERE (ParentId=@ParentId  OR ( ParentID IS NULL and @ParentID IS NULL))

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    SQL Server DeDupe Table 3 25
    SQL Where not exists in same table 3 32
    SQL HELP 2 64
    MS SQL 2005 Srink database in chunks 4 33
    There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
    Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now