Wednesday, September 21, 2011

ISNULL would take the datatype and length of the parameter

In continuation to my earlier post about ISNULL and COALESCE I thought would write one of the basic difference between those two.

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')

No comments: