SQL Server: COALESCE function instead of CASE WHEN – ELSE

Instead of using long “select-case when-else” construction, we can use COALESCE function when we want to check if the value is NULL (this makes the code much shorter)

This is the long CASE WHEN construction:

CASE
WHEN (expression1 IS NULL) THEN 0
ELSE expression1

Here’s the use of COALESCE function

COALESCE(expression1,0)

More info

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s