SQL nullif | nullif Function in SQL - sql - sql tutorial - learn sql
- In SQL Server (Transact-SQL), the NULLIF function compares expression1 and expression2.
- If expression1 and expression2 are equal, the NULLIF function returns NULL.
- Otherwise, it returns the first expression which is expression1.
- The NULLIF function takes two arguments.
- If the two arguments are equal, then NULL is returned.
- Otherwise, the first argument is returned.
- The syntax for NULLIF is as follows:
- It is the same as the following CASE statement:
- For example, let's say we have a table that tracks actual sales and sales goal as below:
- We want to show NULL if actual sales is equal to sales goal, and show actual sales if the two are different.
- To do this, we issue the following SQL statement:
|Shop_Name||NULLIF (Actual, Goal)|