I have the following SQL query
select s.comments + s.further_comments from dbo.samples s where id = 1234
SELECT ISNULL(s.comments, '') + ISNULL(s.further_comments, '') SELECT COALESCE(s.comments, '') + COALESCE(s.further_comments, '')
Replaces NULL with the specified replacement value.
Returns the first nonnull expression among its arguments.
Note that there are some differences between the two methods but for all intents and purposes, they most likely don't apply to your situation.
- ISNULL(NULL, NULL) -- is int
- COALESCE(NULL, NULL) -- Will throw an error
- COALESCE(CAST(NULL as int), NULL) -- it valid and returns int
- ISNULL takes only 2 parameters whereas COALESCE takes variable number of parameters
- COALESCE is based on the ANSI SQL standard whereas ISNULL is a proprietary TSQL function