This question already has an answer here:
I have record in my table where Name column has Null value.. and I want to update that record using below query.. My sql query is:
set @Name=NUll;
update emp set name="gaurav" where name=@Name
When I run this query.. It will not update the record.. It does not compare the value Null
to column value
How can this be done?
Try this
UPDATE emp SET name = "gaurav" WHERE (@name IS NULL AND name IS NULL)
Also you can use following condition with
ISNULL()
Where
'XXXXXXX'
is a unique string constant which can't exist in EMP table;Tests with null values are always false in SQL, except IS NULL or IS NOT NULL. you should add a IS NULL clause to your WHERE:
As per my SQL Knowledge u can store
NULL
in a variable, but can't use it for comparing