The below are the key differences between ISNULL and COALESCE
S.No ISNULL COALESCE
1 Specific to SQL Server ANSI Standard
2 Replaces NULL value with the Re-tuns first non null value among the list of
specified replacement value arguments
3 Uses 2 arguments only Uses any no of arguments
4 Returns the same data type as of It is not guaranteed to return the same data type
first argument as of first argument .
Ex: Ex:
Declare @Str varchar(3) Declare @Str varchar(3)
select isnull(@str,'abcdefgh') 'ISNULL Value' select coalesce(@str,'abcdefgh') 'COALESCE Value'
ISNULL Value COALESCE Value
------------------- -----------------------
abc abcdefgh
S.No ISNULL COALESCE
1 Specific to SQL Server ANSI Standard
2 Replaces NULL value with the Re-tuns first non null value among the list of
specified replacement value arguments
3 Uses 2 arguments only Uses any no of arguments
4 Returns the same data type as of It is not guaranteed to return the same data type
first argument as of first argument .
Ex: Ex:
Declare @Str varchar(3) Declare @Str varchar(3)
select isnull(@str,'abcdefgh') 'ISNULL Value' select coalesce(@str,'abcdefgh') 'COALESCE Value'
ISNULL Value COALESCE Value
------------------- -----------------------
abc abcdefgh
No comments:
Post a Comment