Wednesday, August 5, 2015

SQL SERVER – NULLIF() vs ISNULL()

SQL SERVER – NULLIF() vs ISNULL()

NULLIF() Returns a null value if the two specified expressions are equal. If the Two expressions are not equal then it will return the first expression's value. Whether the returned value is NULL or NOT NULL, NULLIF() will return the same data type as the first expression 
Syntax  : NULLIF(expression1,expression2)
Example 1 :
Select NULLIF(100,50*2)  'NULLIF Value'
OutPut :
image
Example 2 :
Select NULLIF(2*2,2*7)  'NULLIF Value'
OutPut :
image
Example 3 :
Select NULLIF(20-2,19)  'NULLIF Value'
OutPut :
image
ISNULL() Replaces the NULL value with the specified expression value.
Syntax : ISNULL(check expression,replacement value)
Example 1 :
Select ISNULL(null,12) 'ISNULL VALUE'
OutPut :
image
Example 2:
Select ISNULL(marks,0)  'Marks'  from Student
OutPut :
image

No comments: