NULL Functions: ISNULL() and COALESCE()

ISNULL()
Syntax: ISNULL(expression, Replace_value )
--It takes two parameter
--SQL Server Specific
--Return 1st parameter if it is not null.
Example:
 
SELECT ISNULL(NULL, 'SQLServer');
Result: SQLServer
SELECT ISNULL('Inside', 'Forum');
Result: Inside
SELECT ISNULL(NULL, 10);
Result: 10
SELECT ISNULL(18, 88);
Result: 18
SELECT ISNULL(NULL, '2015-10-20');
Result: '2015-10-20'

COALESCE()
Syntax: COALESCE( expression1, expression2, ... expression_n )
 
-It takes multiple parameters
-ANSI Standard
-Return 1st parameter if it is Not NULL.
 
Example:
 
SELECT COALESCE(NULL, 'SQL Server', 'Inside');
Result: SQL Server
SELECT COALESCE(NULL, NULL, 1, 2, 3, NULL, 4);
Result: 1
Difference between ISNULL() and COALESCE()
Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment