NULLIF returns a null value if the two arguments of the function are equal. If the arguments are not equal, NULLIF returns the value of the first argument.
Example:
NULLIF: Suppose that you want to calculate the average earnings of all employees who are eligible to receive a commission. All eligible employees have a commission of greater than 0, and ineligible employees have a value of 0 for commission:
SELECT AVG(SALARY+NULLIF(COMM,0))
AS “AVERAGE EARNINGS”
FROM EMP;The result table looks like this:
AVERAGE EARNINGS
================
35248.8461538
Ref: IBM
Ref: IBM






