SQLServer Get Results Where Value Is Null

I have a sql server database that I am querying and I want to get information only if a specific row is zero. I used the where statement, for example:

WHERE database.foobar = NULL

and returns nothing. However, I know that there is at least one result, because I created an instance in the database where foobar is zero. If I select the where statement, it will display the data, so I know this is not the rest of the query.

can someone help me

+3
source share
4 answers

The correct syntax is WHERE database.foobar IS NULL. See http://msdn.microsoft.com/en-us/library/ms188795.aspx for more details.

+7
source

Comparison with NULL will be false every time. Instead, you want to use IS NULL.

x = NULL -- always false x <> NULL -- always false x IS NULL -- these do what you want x IS NOT NULL 
+3
source

Read Testing for Null Values , You Need IS NULL not = NULL

+2
source

Is this a SQL Server database? If so, use IS NULL instead of comparison ( MSDN ).

+1
source

All Articles