Reputation: 63
I have a table with a few NULL values in an integer column and I set one of those values to 2.
I have tested the statement by replacing those NULL values with numbers, and the statement updates the values correctly, however whenever I try to update a NULL value, it just stays NULL.
in the context of this app, the value could be either NULL, 0 or 1, and at this point would run an UPDATE command to set the value to 2. it works for the 0s and 1s, and works if i replace null values with something else such as a 9, however it would be convenient to leave them as NULL- But it doesn't update as NULL!
How would I go about fixing this?
Upvotes: 0
Views: 4611
Reputation: 96455
You are probably using WHERE column = NULL
in your UPDATE statement to determine the rows that should be updated.
In SQL, you can not compare a value for equality to NULL using the equal sign =
, the normal comparison operator – for targeting NULL-values, you have to use IS_NULL
instead, so
WHERE column IS_NULL
Upvotes: 6