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
Mark
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
veljasije
source
to share
When @color is NULL
replaced with ''
.
So when @color
is ( NOT NULL OR''
) will be executed BEGIN .. END
.
+2
Ralf de Kleine
source
to share