Sql server : COALESCE function with example - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

Sql server : COALESCE function with example

Here in this article I am going to explain COALESCE function of sql server with example.

Description:
The COALESCE function takes comma separated list of arguments of same data type sbut returns the value of the first non-NULL argument.

Syntax:
COALESCE( expression1,[....n] )

 Example:
I have created a table Employee and insert some dummy data into it. 

Sql server  : COALESCE function with example

Now you can see in last 2 record status of employee is null. I want to replace null with 0. Run the below given query and check output.

select  name,COALESCE(Status,0) as 'status' from Employee

Output:

Sql server  : COALESCE function with example

  


What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon