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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s