CadencePlus Solutions

Type conversion and NULL handling

A calculation should distinguish missing information, zero values, invalid types, and undefined results.

CAST

CAST(value AS type) requests a conversion. SQLite has flexible typing and may convert invalid numeric text to zero; it is not a substitute for validating input. SQL Server TRY_CAST and PostgreSQL casts have different behavior.

COALESCE

COALESCE returns the first non-NULL argument. Use COALESCE(email, 'Not supplied') for a display label. Replacing unknown revenue with zero is a business assumption, not a neutral formatting choice.

NULLIF

NULLIF(a,b) returns NULL when a equals b. sales / NULLIF(target,0) avoids a zero denominator and signals that the ratio is undefined instead of inventing a performance score.

Numeric division

SQLite integer division can truncate an answer. Use a real operand such as 1.0 or CAST(... AS REAL) when a fractional result is intended. Other engines have their own numeric precision rules.