Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 What Is th difference between Is Null & COALESCE

Author  Topic 

Posting Yak Master

125 Posts

Posted - 2008-02-04 : 09:08:30
WHATS the basic diff. between Is Null and Coalesce can someone help me regarding this

Rahul Arora
07 Batch
NCCE Israna,


Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-04 : 09:12:54
Keyword "IS NULL" is a check to see if value IS NULL.
Function "ISNULL()" returns second parameter is first parameter IS NULL.
Function "COALESCE()" returns first parameter that NOT IS NULL.

Read Books Online for more in-depth explanation.

E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-04 : 09:26:11
Adding to above:-

COALESCE works the same way as CASE WHEN. As such it requires all its expressions to be of same datatype. execute this and see:-
Print COALESCE('An String','12')
and also

Print COALESCE('An String',12)

Whereas you can use ISNULL to work like this:-

Print ISNULL('An String',12)

But problem with ISNULL is the return datatype will same as type of first expression. See this:-

DECLARE @Str varchar(5)
Print ISNULL(@Str,'cdwfergthtyjukuikil')
this will return only first 5 characters as @str is of type varchar(5).

This is clearly suggested in BOL as:-

The value of check_expression is returned if it is not NULL; otherwise, replacement_value is returned after it is implicitly converted to the type of check_expression, if the types are different.
see the definition of COALESCE which says:-

If all arguments are NULL, COALESCE returns NULL.

COALESCE(expression1,...n) is equivalent to this CASE function:

WHEN (expression1 IS NOT NULL) THEN expression1
WHEN (expressionN IS NOT NULL) THEN expressionN
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 2008-02-28 : 07:39:40


Failing to plan is Planning to fail
Go to Top of Page

- Advertisement -