SQL nullif
returns the value of the first argument unless it equals the second argument—then it returns the null
value.
SELECT NULLIF(string_value, 'unknown')
FROM …
The example returns the value of string_value
unless it contains the the text unknown
—then it returns the SQL null
value.0
Tutorials: Null
— Absent Data, Case
— Conditional Expressions
Other forms: case … when …
(simple case), case when …
(searched case).
The nullif
expression is defined in ISO/IEC 9075:2016-2 as mandatory feature F261-03.
The essence of SQL tuning in 200 pages
Buy on Amazon
(paperback only)
Paperback and PDF also available at Markus’ store.
Markus offers SQL training and consulting for developers working at companies of any size.
Learn more »
The rules how strings are match (e.g. case sensitive or not) depend on the effective collation
.