Complete the code to return NULL if the two values are equal.
SELECT NULLIF(10, [1]);
The NULLIF function returns NULL if both arguments are equal. Here, 10 equals 10, so the result is NULL.
Complete the code to return the second value if the first is not equal to it.
SELECT NULLIF(5, [1]);
NULLIF returns the first argument if it is not equal to the second. Here, 5 is not equal to 10, so it returns 5.
Fix the error in the code to correctly use NULLIF with column names.
SELECT NULLIF(price, [1]) FROM products;Column names should not be in quotes. Using price without quotes refers to the column correctly.
Fill both blanks to return NULL if quantity equals 0, else return quantity.
SELECT NULLIF([1], [2]) AS result FROM inventory;
NULLIF(quantity, 0) returns NULL if quantity is 0, else returns quantity.
Fill all three blanks to return NULL if status equals 'inactive', else return status in uppercase.
SELECT NULLIF(UPPER([1]), [2]) AS status_upper FROM users WHERE [3] = 'inactive';
We convert status to uppercase and compare it to 'INACTIVE' to return NULL if equal. The WHERE clause filters rows where status is 'inactive'.