| Author: Hari 02 Nov 2009 | Member Level: Gold | Rating:  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 2009 | Member Level: Diamond | Rating:  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
|