In continuation to my earlier post about ISNULL and COALESCE I thought would write one of the basic difference between those two.
DECLARE @strTest VARCHAR(10)
SET @strTest = NULL
--it would return only 'Enter some'
SELECT ISNULL(@strTest, 'Enter some value')
In this case, ISNULL would return only any output which is lesser or equal to 10 characters because the variable used as its first parameter is defined as VARCHAR(10)
--it would return the complete string!
SELECT COALESCE(@strTest, 'Enter some value')
DECLARE @strTest VARCHAR(10)
SET @strTest = NULL
--it would return only 'Enter some'
SELECT ISNULL(@strTest, 'Enter some value')
In this case, ISNULL would return only any output which is lesser or equal to 10 characters because the variable used as its first parameter is defined as VARCHAR(10)
--it would return the complete string!
SELECT COALESCE(@strTest, 'Enter some value')
Comments