tags:

views:

109

answers:

4

I have a sql server database that I am querying and I only want to get the information when a specific row is null. I used a where statement such as:

WHERE database.foobar = NULL

and it does not return anything. However, I know that there is at least one result because I created an instance in the database where 'foobar' is equal to null. If I take out the where statement it shows data so I know it is not the rest of the query

can anyone help me out

+6  A: 

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

bdukes
+1  A: 

Is it an SQL Server database? If so, use IS NULL instead of making the comparison (MSDN).

Farinha
+2  A: 

Read Testing for Null Values, you need IS NULL not = NULL

SQLMenace
+3  A: 

Comparison to NULL will be false every time. You want to use IS NULL instead.

x =  NULL      -- always false
x <> NULL      -- always false

x IS NULL      -- these do what you want
x IS NOT NULL
Mark Harrison