Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
NULL and Predicates: Three-Valued Logic, LIKE, IN, BETWEEN and COALESCE
In SQL a comparison has three outcomes: TRUE, FALSE and UNKNOWN; that is why = NULL finds no rows, NOT on a nullable column also drops the NULL rows, and a single NULL in a NOT IN list empties the result. We show the type difference between COALESCE and ISNULL, guarding division by zero with NULLIF, escaping in LIKE and how a leading % affects the index, and how BETWEEN misses the last day of a date range, with real output.
Sentinel Values: The Hidden Cost of 0, -1, "1900-01-01" and 9999-12-31
Sentinel values (0 in salary, 9999-12-31 in an end date, 1900-01-01 in a date) silently corrupt aggregates: in the example the average salary comes out as 51,000 instead of 85,000. The fix is usually a nullable column, a separate state field when absence has several meanings and a Special Case type in the domain; a sentinel can be a deliberate standard only when a single producer owns it (temporal tables, a persisted computed column).
Operators and Expressions in C#: Short-Circuiting, ??, ?. and Precedence
Expressions versus statements in C#, arithmetic and compound assignment, prefix and postfix increments, comparison, logical operators and short-circuiting, the ?: operator, handling null with ??, ??= and ?., and precedence traps such as 100 - discount ?? 0.