Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Not Equal in where clause eliminating Nulls

Posted on 2009-05-08
6
Medium Priority
?
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

Expert Comment

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

Open in new window

0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 24340707
Try this:
SELECT *
FROM your_table_name
WHERE ISNULL(ActivityStatusId, 0) <> 100

Open in new window

0
 
LVL 3

Accepted Solution

by:
xbrady earned 2000 total points
ID: 24340708
You can use something like this:
(ActivityStatusId IS NULL OR ActivityStatusId <> 100)
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24340711
where ActivityStatusId <> 100 or ActivityStatusId IS NULL
0
 

Expert Comment

by:idlir
ID: 24341301
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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24342915
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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

722 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