TSQL ISNULL VS COALESCE

One of the difference between the two is that ISNULL is just checking the first argument null ability. As for COALESCE is it used to return the first non-nullable value in the argument list.

Another important thing to note is that ISNULL result type is based on the first argument type. On the other hand CAOLESCE will return the result type based on the argument type.

DECLARE
@x as varchar(2) = NULL
,@y AS VARCHAR(3) = '123'

select coalesce(@x,@y)

Returns : 123

SELECT ISNULL(@x,@y)

Returns: 12
Advertisements