Solved

Not Equal in where clause eliminating Nulls

Posted on 2009-05-08
6
191 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]
ID: 24340703
NULL must be handled :
where ( ActivityStatusId <> 100 OR ActivityStatusId IS NULL )

Open in new window

0
 
LVL 59

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 500 total points
ID: 24340708
You can use something like this:
(ActivityStatusId IS NULL OR ActivityStatusId <> 100)
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to 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 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

776 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