Questions tagged [nullif]

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.

61 questions
-1
votes
1 answer

using MIN and NULLIF correctly

$min_cost = min(NULLIF(value, 0))($cost_1, $cost_2, $cost_3, $cost_4); Some costs on the database return $0.00, so that automatically becomes the $min_cost, even though there is values of more than zero on the other costs I cant find much info on…
botch
  • 15
  • 5
1 2 3 4
5