SQL Server Coalesce

Coalesce is one of those old functions that has been around for a very long time and lost some of it’s lime light. It is good for a number of things but it’s VERY important to know how it behaves.

Overview

So coalesce takes any two or more parameters and takes the first parameter which IS NOT NULL and returns that value. For example:

SELECT COALESCE(null,’  ‘, ‘value’);

This would return the second argument, ‘ ‘, not the value ‘value’. You need to be very careful with this! Sometimes programmers don’t recognize the difference between null and empty values. If that is you, I have a very good article discussing null values in SQL Server, listed below:

SQL Server Null Values ~ Into the Void (pun intended)
Advertisements

One thought on “SQL Server Coalesce

Have an opinion? Leave an opinion!

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s