thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Intermediate

NULLIF Function

A function that returns NULL if its two arguments are equal, otherwise the first argument.

Definition

NULLIF is most often used to avoid divide-by-zero errors, because dividing by NULL yields NULL instead of raising an error. It can also turn placeholder values such as empty strings into proper NULLs.

Example

SELECT Revenue / NULLIF(Units, 0) AS PricePerUnit FROM Sales;

Exam tip

For safe division in SQL use x / NULLIF(y, 0); in DAX use DIVIDE().

Related terms