• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

Howto select articles with ParentId = NULL?

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
)
AS

SELECT Id, [Name]  FROM tblContent  WHERE ParentId=@ParentId
0
webressurs
Asked:
webressurs
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
like this:

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

SELECT Id, [Name]  FROM tblContent  WHERE (ParentId=@ParentId  OR ( ParentID IS NULL and @ParentID IS NULL))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now