Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2005
 COALESCE (SQL Server Compact Editio...
Collapse All/Expand All Collapse All
SQL Server 2005 Compact Edition Books Online
COALESCE (SQL Server Compact Edition)

Returns the first nonnull expression among its arguments.

COALESCE ( expression [ ,...n ] ) 
expression

An expression of any data type.

n

A placeholder indicating that multiple expressions can be specified. All expressions must be of the same type or must be implicitly convertible to the same type.

Returns the highest precedence type from the set of types in expression.

In this example, a table includes three columns with information about an employee's yearly wage: hourly_wage, salary, and commission. However, an employee receives only one type of pay. To determine the total amount paid to all employees, use the COALESCE function to receive only the nonnull value found in the hourly_wage, salary, and commission columns.

SELECT CONVERT(money, COALESCE(hourly_wage * 40 * 52, 
salary, commission * num_sales)) AS "Total Salary" 
FROM wages
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker