C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Uses of Coalesce function in SQLSERVER


Posted Date: 02 Nov 2009      Posted By: Christopher      Member Level: Gold     Points: 1   Responses: 2



hi,

What are all the uses of Coalesce functions





Responses

Author: Hari    02 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Coalesce returns the first non-null expression among its arguments.

Lets say we have to return a non-null from more than one column, then we can use COALESCE function.


SELECT COALESCE(hourly_wage, salary, commission) AS 'Total Salary' FROM wages

In this case,

If hourly_wage is not null and other two columns are null then hourly_wage will be returned.
If hourly_wage, commission are null and salary is not null then salary will be returned.
If commission is non-null and other two columns are null then commission will be returned.

You can check this url as well
http://www.mssqltips.com/tip.asp?tip=1521



Author: Danasegarane.A    02 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

This full will return first non null value from the condition

For example. Take this query


Select CoalEsce(null,1)


outputs

1


and


Select CoalEsce(1,null,100)


outputs


1


Thanks and Regards,
Danasegarane Arunachalam



Post Reply
You must Sign In to post a response.
Next : How to display one column in different ways
Previous : DateTime
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use