Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to update image column with A string where Its Is NULL Now..But
Its not working...My Query Below..
Any One Can Explain me why Its Happens..

update Info set image='Image/defalt.png' where Image=null
Posted
Comments
[no name] 26-May-14 12:17pm    
What is it that you think "Its not working" means?

try below
SQL
UPDATE
      Info 
SET
    image='Image/defalt.png' 
WHERE
   Image IS NULL


Quote:
How can we test for NULL values?

It is not possible to test for NULL values with comparison operators, such as =, <, or <>.

We will have to use the IS NULL and IS NOT NULL operators instead.
Reference[^]
 
Share this answer
 
v2
Comments
Ziee-M 26-May-14 12:35pm    
my 5, i never thought about it, now its saved deeep in my brain! (talking about the info in the bottom)
Maciej Los 26-May-14 15:06pm    
+5Have a look at my answer ;)
Strictly saying: it's impossible to use comparison operators, like: <, > or =.
Have a look here: NULL Comparison Search Conditions[^]

To use comparison operators with NULL, use COALESCE[^] function, which evaluates NULL values with other.
Sample 1
SQL
SELECT IntField
FROM TableName
WHERE COALESCE(IntField, 0) = 0

Sample 2
SQL
SELECT StringField
FROM TableName
WHERE COALESCE(StringField, '') = ''
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 26-May-14 15:23pm    
It is important to know that there is a SQL function - ISNULL that has the same format and purpose that of COALESCE.
The main difference that the first parameter can be evaluated twice in COALESCE (in case when the parameter not a single column but a sub-query), once for the check and once for the return if the first attempt yields no-null value. This behavior can lead to some surprises, as the two runs can yield different values...
The meaning of all this that ISNULL is safer for most purposes (and has better performance too)...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900