Class NullIf
- Namespace
- YndigoBlue.Velocity.Functions
- Assembly
- YndigoBlue.Velocity.dll
Represents the NULLIF function that returns NULL if two expressions are equal, otherwise returns the first expression.
public class NullIf : Function, ICheckItem, IDefaultItem, IFilterItem, IElement
- Inheritance
-
NullIf
- Implements
Remarks
The NULLIF function compares two expressions and returns NULL if they are equal, otherwise it returns the first expression. This is equivalent to: CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END. NULLIF is useful for converting specific values to NULL (e.g., converting empty strings or sentinel values like -1 to NULL), preventing division by zero, or normalizing data.
Examples
Return null instead of zero to avoid division-by-zero errors:
var schema = manager.LoadSchema("finance");
var accounts = schema["accounts"];
var query = new Query()
.Select([ accounts["id"], new Expression("safe_balance", new NullIf(accounts["balance"], 0.0)) ])
.From(accounts);
var results = manager.Retrieve(query);
Constructors
- NullIf(IElement, IElement)
Initializes a new instance of NULLIF with generic element-based arguments.
- NullIf(Column, double)
Initializes a new instance of NULLIF with a column and a double literal.
- NullIf(Column, int)
Initializes a new instance of NULLIF with a column and an integer literal.
- NullIf(Column, string)
Initializes a new instance of NULLIF with a column and a string literal.
- NullIf(Column, Column)
Initializes a new instance of NULLIF with column-based expressions.
- NullIf(Expression, Expression)
Initializes a new instance of NULLIF with expression-based arguments.