Returns a null value if the arguments are equal, otherwise it returns the value of the first argument.
NULLIF Example
SELECT item, NULLIF(cost, -1)
FROM inventory;
For this example, say that a cost value of -1 indicates no cost at all. With the .NULLS system variable set to ‘N/A’, it might be more informative to return a null value instead of -1. Using the NULLIF function, a null value can be substituted for every return of -1.
The equivalent (simple) CASE expression for this example would be the following:
SELECT item,
CASE cost
WHEN -1 THEN NULL
ELSE cost
END
FROM inventory;