?
Solved

Howto select articles with ParentId = NULL?

Posted on 2007-10-21
1
Medium Priority
?
433 Views
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
)
AS

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

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 20117269
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

840 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