Vivek Thakur

Chaotically Complex

  Home  |   Contact  |   Syndication    |   Login
  102 Posts | 1 Stories | 317 Comments | 66 Trackbacks

News



Archives

ASP.NET Ventures

COALESCE(arg1,arg2,...) is a pretty useful function in SQL. Suppose we have a table A having 3 columns FullName, CompleteName and DisplayName. Any of these columns can contain null values. Now we want to select the DisplayName from this table, but if it is null, then return FullName, if that is also null then return CompleteName. We can easily perform the same in one select statement as:

SELECT COALESCE(DisplayName, FullName, CompleteName) From A

This will return the first non-null value. And best thing is that COALESCE is an ANSI standard.

Here is a nice comparison of CAOLESCE() and ISNULL() (which is a T SQL function):

http://databases.aspfaq.com/database/coalesce-vs-isnull-sql.html

 

 

posted on Saturday, December 30, 2006 1:27 AM

Feedback

# re: COALESCE function in SQL 9/29/2008 9:40 PM Blutch
Hi,
thank you very much, it's a good explanation for the coalesce function.


# re: COALESCE function in SQL 10/16/2008 12:32 AM Kashif Mohammed
Hi,
Indeed this is really short and beautiful explanation and is well understood by beginners like me.

# re: COALESCE function in SQL 12/3/2008 11:44 AM Kumar Saurabh
a good explanation - which makes the functionality very clear.

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 7 and 2 and type the answer here: