Vivek Thakur

Chaotically Complex

  Home  |   Contact  |   Syndication    |   Login
  105 Posts | 1 Stories | 498 Comments | 65 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.

# re: COALESCE function in SQL 2/2/2009 5:09 PM kalyani M
good Explanation.sufficient enough to understand for beginners.

# re: COALESCE function in SQL 3/5/2009 10:17 AM Manohar
Nice explanation to understand COALESCE function.

# re: COALESCE function in SQL 5/4/2009 7:17 PM MEE
Have to agree---This was plain english, and is a good base to understanding the more complex uses

# re: COALESCE function in SQL 6/17/2009 7:32 AM sachin
Precise explanation.......
really very good than other sites

# re: COALESCE function in SQL 7/20/2009 2:14 AM yes
very good...

# re: COALESCE function in SQL 8/12/2009 1:36 AM Vijay Karthik J
simply superb

# re: COALESCE function in SQL 9/14/2009 3:20 AM avie
vry nice

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: