Pages

Men

rh

6/03/2012

COALESCE Function in SQL Server

COALESCE:
Coalesce in the Select statement below.

Exmaple:  SELECT Coalesce(Primaryemail, null)
Selects Primary Email if it is not null.

Exmaple:  SELECT Coalesce(null, Secondaryemail)
If the Primary email is null then it selects Secondary Email.

Exmaple:  SELECT Coalesce(Primaryemail, Secondaryemail)
If the Primary Email is not null and Secondary Email is not null then primary email will be selected.


So COALESCE returns the first not null column among the list of Columns passed.

Exmaple:  SELECT Coalesce(null, null)
If both are null then it returns null

No comments :

Post a Comment