Sqlserver - COALESCE

COALESCE

Returns the first nonnull expression among its arguments.
Syntax
COALESCE ( expression [ ,...n ] )


Limitations of COALESCE():
In COALESCE() while passing arguments,it does not support arguments with different data types in few cases.

For example: 

SELECT COALESCE('A',GETDATE())
GO


-----------------------

Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.


But ISNULL() can handle this

SELECT ISNULL('A',GETDATE())
GO



----
A
(1 row(s) affected)

Tricky Example:
DECLARE @T VARCHAR(100)
SELECT @T = COALESCE(@T+', ','' )+NAME FROM SYS.TABLES SELECT @T

2 comments:

Anonymous said...

Touche. Solid arguments. Keep up the amazing spirit.


My favorite web log regarding technological know-how: website

Anonymous said...

I am not sure where you are getting your info, but good topic.
I needs to spend some time learning much more or understanding more.
Thanks for wonderful info I was looking for this info for my mission.


Take a look at my web blog :: Houston Texas public adjuster