More
Image
What is different between nullif and isnull
By JC.Adinarayana Reddy On 07 Jan 2017
Categories: Sql Server
NULLIF :
  • It is a Function 
  • Returns a NULL value if the two specified expressions are equal 
  • Returns first expression, If the specified expressions are NOT equal 
 
/*Both expressions(@A and @B) are Equal*/ 
 
Declare @A Int, @B Int
Select @A = 100, @B = 100
Select NULLIF(@B, @A) [Result]
 
Result 
NULL
 
/*Both expressions(@A and @B) are NOT Equal*/
 
 
Declare @A Int, @B Int
Select @A = 100, @B = 101
Select NULLIF(@B, @A) [Result]
 
Result 
101 
 
 
ISNULL :
  • It is a Function 
  • Returns second Expression, If the first one is NULL 
  • Returns first expression, If the first one is NOT NULL 
 
Declare @A Int
Select @A = 100
Select ISNULL(@A,0) [Result]
 
Result 
100
 

Comments
Message :
Comments
JC.Adinarayana Reddy
.net
.net