A general SQL function
that returns the value of the first expression that is not NULL.
Synopsis
COALESCE(expression,expression)
The
COALESCE function returns the value of the
first non-NULL expression in the expression list. If all expressions evaluate
to NULL, NULL is returned.
The type of the return value for the function is the same as the type
of the expressions. Currently, Caché always returns a type of %String/VARCHAR.
The following example uses
COALESCE to determine
which records contain null values for the FavoriteColors field. It returns
a single column. When FavoriteColors is non-null, the color preference is
returned; when FavoriteColors is null, the name of the person with no color
preference is returned:
SELECT COALESCE(FavoriteColors,Name) AS WhoNullColors
FROM Sample.Person