Monday, May 10, 2010

Comparing NULL values

Hi,
While implementing the logical flow in stored procedures, data comparison is a common scenario with NULL data.
We can handle the NULL data comparison in simple steps.
The simple script for the comparison:

DECLARE @VARIABLE1 char(10)
DECLARE @VARIABLE2 char (10)

IF (ISNULL(@VARIABLE1,0)= ISNULL(COALESCE(@VARIABLE2,@VARIABLE1),0))
--IF(@VARIABLE1 = @VARIABLE2)

        SELECT 1 AS RESULT

ELSE

       SELECT 100 AS RESULT
 
here are some cases of comparisons
 
1. Enable the direct IF(@VARIABLE1 = @VARIABLE2) statement and disable the existing logic for the same case -- Now see the result --funny of SQL


2. Giving values to the variables.
 
Thanks
prav
 

No comments:

Post a Comment