Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get SQL to recognize WHERE column = NULL?

In microsoft SQL, I have the following statement (roughly):

UPDATE sometable 
   SET somecolumn = @somevalue 
 WHERE somecolumn = NULL;

@somevalue is set previously in the script.

This runs fine and SQL tells me zero rows are affected. There are five rows were somecolumn is NULL. What am I doing wrong?

like image 321
Peter Avatar asked Jun 29 '11 20:06

Peter


1 Answers

You have to use IS NULL instead to test for a NULL value in the column.

 UPDATE sometable SET somecolumn = @somevalue WHERE somecolumn IS NULL;
like image 92
Joe Stefanelli Avatar answered Oct 11 '22 20:10

Joe Stefanelli