SQL - Refinement - ISNULL ()

I have the following logic in a stored procedure.

What's going on here?

If the color is null, replace it with ''

IF ISNULL(@color, '') <> '' 
BEGIN
END

      

+3


source to share


2 answers


This is the same as:

IF (@color IS NOT NULL AND @color <> '') 
   THEN ...

      



One more thing, try using a COALESCE

function instead ISNULL

, because SQL Standard is suggested first. The syntax is very similar:

IF COALESCE(@color, '') <> '' 
BEGIN
    ...
END

      

+4


source


When @color is NULL

replaced with ''

.



So when @color

is ( NOT NULL OR''

) will be executed BEGIN .. END

.

+2


source







All Articles