Solved

Not Equal in where clause eliminating Nulls

Posted on 2009-05-08
6
189 Views
Last Modified: 2012-05-06
Hello,

I have this query with a condition in where clause ActivityStatusId <> 100
but in the resultset it is eliminating nulls too.

How do I get around this one.

Thanks
0
Comment
Question by:rowmark
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
NULL must be handled :
where ( ActivityStatusId <> 100 OR ActivityStatusId IS NULL )

Open in new window

0
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
Try this:
SELECT *

FROM your_table_name

WHERE ISNULL(ActivityStatusId, 0) <> 100

Open in new window

0
 
LVL 3

Accepted Solution

by:
xbrady earned 500 total points
Comment Utility
You can use something like this:
(ActivityStatusId IS NULL OR ActivityStatusId <> 100)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
Comment Utility
where ActivityStatusId <> 100 or ActivityStatusId IS NULL
0
 

Expert Comment

by:idlir
Comment Utility
That is because a null value is undetermined, therefore it cannot be verified whether it's different from 100

If your condition is eliminating the null values, use the following

where coalesce(ActivityStatusId ,0) <> 100


This will return all the rows that have an ActivityStatusId with a predetermined value, and all those that are null (coalesce replaces null with 0 and 0 is always different from 100 )
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
rowmark,

  glad you got your solution.
  note though that for fairness, if people post the same or alternative good solutions at the same time, you should really do a split instead of accept one of them!

angel eyes, zone advisor
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

743 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

17 Experts available now in Live!

Get 1:1 Help Now