Table of Contents

Class Coalesce

Namespace
YndigoBlue.Velocity.Functions
Assembly
YndigoBlue.Velocity.dll

Represents the COALESCE function that returns the first non-null value from a list of expressions.

public class Coalesce : Function, ICheckItem, IDefaultItem, IFilterItem, IElement
Inheritance
Coalesce
Implements

Remarks

The COALESCE function evaluates arguments from left to right and returns the first non-null value. If all arguments are null, COALESCE returns null. This is useful for providing default values, handling optional data, or consolidating values from multiple nullable columns. For example, COALESCE(col1, col2, 'N/A') returns col1 if not null, otherwise col2 if not null, otherwise 'N/A'.

Examples

Return the first non-null contact number from three possible columns:

var schema = manager.LoadSchema("crm");
var contacts = schema["contacts"];

var query = new Query()
    .Select([ contacts["id"], new Expression("contact_number", new Coalesce([ contacts["mobile"], contacts["phone"], contacts["fax"] ])) ])
    .From(contacts);

var results = manager.Retrieve(query);

Constructors

Coalesce(IEnumerable<IElement>)

Initializes a new instance of COALESCE with a collection of elements.