Click here to Skip to main content
15,896,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select * from tbl_name
where ISNULL(ID,0) = xxx


Here in above statement ,

if xxx = 0 then what is ISNULL(ID,0)
if xxx = 1 then what is ISNULL(ID,0)
if xxx = 122 then what is ISNULL(ID,0)

how does ISNULL(ID,0) works in where condition
Posted
Updated 23-Nov-14 16:12pm
v2

SQL
isnull Replaces NULL with the specified replacement value.

SQL
ISNULL(ID,x) replaces all the null value of ID with x
where x= has a value.


SQL
where Id=0(without isnull check) means it'll skip all the ID containing the null value in the table.
and there is another problem that there are some datatype that are not comparable with the null value so in that case you can get the comparison error.
so, using isnull(ID,0) is used to set all the null value of ID by 0 and then coparing to the condition value(xxx).


for more info check this..
http://msdn.microsoft.com/en-us/library/ms184325.aspx[^]
 
Share this answer
 
Comments
Maciej Los 24-Nov-14 2:10am    
+5
/\jmot 24-Nov-14 2:30am    
thanks.
ISNULL(ID,0) will return zero if the ID column is null, otherwise it returns ID column value, So:
SQL
if xxx = 0  -- give you 0
if xxx = 1  -- give you 1
if xxx = 122 -- give you 122
 
Share this answer
 

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