NULLIF is an ISO/ANSI SQL standard function that takes two arguments. If the two arguments are equal, then the NULL value is returned. Otherwise, the first argument is returned.
The NULLIF function takes two arguments. If the two arguments are equal it returns NULL. Otherwise, the first argument is returned.
Syntax:
NULLIF ( <expression 1>, <expressions 2> )
It is the same as the following CASE expression:
CASE WHEN <expression 1> = <expression 2> THEN NULL
ELSE <expression 1>
END
FROM <table>;
In action:
SELECT NULLIF(100, 100); -- the same values, NULL
Result: NULL
SELECT NULLIF(101, 100); -- different values, returns the first.
Result: 101
It is available in MS SQL Server, SQL, Oracle, Teradata, etc.