I rather think that
NULLIF(A, B)
is syntactic sugar for
CASE WHEN A = B THEN NULL ELSE A END
But you are correct: it is mere syntactic sugar to aid the human reader.
W3Schools
w3schools.com โบ sql โบ func_sqlserver_nullif.asp
SQL Server NULLIF() Function
SQL Examples SQL Editor SQL Quiz SQL Exercises SQL Server SQL Syllabus SQL Study Plan SQL Bootcamp SQL Certificate SQL Training ... The NULLIF() function returns NULL if two expressions are equal, otherwise it returns the first expression.
Videos
53:00
SQL NULL Functions | COALESCE, ISNULL, NULLIF, IS (NOT) NULL | ...
08:49
Using SQL NULLIF with Missing Values | Essential SQL - YouTube
06:07
SQL SERVER||NULLIF Function in SQL and use case of NULLIF - YouTube
08:46
SQL Functions Demystified: Mastering NULLIF, NVL, NVL2, NULLIF ...
21. NULLIF() | SQL NULL FUNCTION | SQL Server Tutorial PART 21 ...
11:54
ISNULL AND NULLIF IN SQL | Advanced SQL | Ashutosh Kumar - YouTube
Top answer 1 of 5
9
I rather think that
NULLIF(A, B)
is syntactic sugar for
CASE WHEN A = B THEN NULL ELSE A END
But you are correct: it is mere syntactic sugar to aid the human reader.
2 of 5
8
I often use it where I need to avoid the Division by Zero exception:
SELECT
COALESCE(Expression1 / NULLIF(Expression2, 0), 0) AS Result
FROM โฆ
W3Schools
w3schools.com โบ sql โบ func_mysql_nullif.asp
MySQL NULLIF() Function
SQL Examples SQL Editor SQL Quiz SQL Exercises SQL Server SQL Syllabus SQL Study Plan SQL Bootcamp SQL Certificate SQL Training ... The NULLIF() function compares two expressions and returns NULL if they are equal.
Snowflake Documentation
docs.snowflake.com โบ en โบ sql-reference โบ functions โบ nullif
NULLIF | Snowflake Documentation
SELECT a, b, NULLIF(a,b) FROM i; --------+--------+-------------+ a | b | nullif(a,b) | --------+--------+-------------+ 0 | 0 | [NULL] | 0 | 1 | 0 | 0 | [NULL] | 0 | 1 | 0 | 1 | 1 | 1 | [NULL] | 1 | [NULL] | 1 | [NULL] | 0 | [NULL] | [NULL] | 1 | [NULL] | [NULL] | [NULL] | [NULL] | --------+--------+-------------+
Oracle
docs.oracle.com โบ en โบ database โบ oracle โบ oracle-database โบ 26 โบ sqlrf โบ NULLIF.html
SQL Language Reference
1 month ago - NULLIF compares expr1 and expr2. If they are equal, then the function returns null. If they are not equal, then the function returns expr1.
W3Schools
w3schools.com โบ sql โบ sql_isnull.asp
W3Schools.com
String Functions: ASCII CHAR_LENGTH ... CAST COALESCE CONNECTION_ID CONV CONVERT CURRENT_USER DATABASE IF IFNULL ISNULL LAST_INSERT_ID NULLIF SESSION_USER SYSTEM_USER USER VERSION SQL Server Functions...
IBM
ibm.com โบ docs โบ en โบ db2-for-zos โบ 12.0.0
NULLIF scalar function - Db2 SQL
The NULLIF function returns the null value if the two arguments are equal; otherwise, it returns the value of the first argument.
MSSQLTips
mssqltips.com โบ home โบ sql coalesce, isnull, nullif in sql server, oracle and postgresql
SQL COALESCE, ISNULL, NULLIF in SQL Server, Oracle and PostgreSQL
March 21, 2022 - There is another expression/function present in all three RDBMS that is used with NULL and that is NULLIF(). This last function has two arguments and returns NULL if both arguments are equal, otherwise it returns the first argument.
SQLServerCentral
sqlservercentral.com โบ forums โบ topic โบ nullif-and-0
NULLIF and 0 โ SQLServerCentral Forums
March 25, 2021 - The NULLIF function returns NULL if the 2 arguments are equal, otherwise it just returns the first argument. The first and third expressions are clearly equivalent expressions, so return NULL.
DotFactory
dofactory.com โบ sql โบ nullif
SQL NULLIF Function
The NULLIF function returns NULL if two specified values are equal.
Salesforce Developers
developer.salesforce.com โบ docs โบ atlas.en-us.bi_dev_guide_sql.meta โบ bi_dev_guide_sql โบ bi_sql_nullif.htm
NULLIF() | SQL for Analytics Developer Guide | Salesforce Developers
Use the nullif() function as shorthand for a searched case statement where two equal expressions return null.
TechOnTheNet
techonthenet.com โบ sql_server โบ functions โบ nullif.php
SQL Server: NULLIF Function
In SQL Server (Transact-SQL), the NULLIF function compares expression1 and expression2. If expression1 and expression2 are equal, the NULLIF function returns NULL.