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.
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › language-elements › nullif-transact-sql
NULLIF (Transact-SQL) - SQL Server | Microsoft Learn
Copy CREATE TABLE budgets ( dept TINYINT, current_year DECIMAL(10,2), previous_year DECIMAL(10,2) ); INSERT INTO budgets VALUES(1, 100000, 150000); INSERT INTO budgets VALUES(2, NULL, 300000); INSERT INTO budgets VALUES(3, 0, 100000); INSERT INTO budgets VALUES(4, NULL, 150000); INSERT INTO budgets VALUES(5, 300000, 300000); SELECT dept, NULLIF(current_year, previous_year) AS LastBudget FROM budgets; Here's the result set. dept LastBudget ---- ----------- 1 100000.00 2 null 3 0.00 4 null 5 null · CASE (Transact-SQL) decimal and numeric (Transact-SQL) System Functions (Transact-SQL)
Videos
53:00
SQL NULL Functions | COALESCE, ISNULL, NULLIF, IS (NOT) NULL | ...
06:07
SQL SERVER||NULLIF Function in SQL and use case of NULLIF - YouTube
08:49
Using SQL NULLIF with Missing Values | Essential SQL - YouTube
07:17
SQL NULLIF function: How to Use the NULLIF Function - YouTube
07:07
Differences between ISNULL and NULLIF - YouTube
02:07
SQL NULLIF Function - how to use NULLIF Function - YouTube
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.
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.
Oracle
docs.oracle.com › en › database › oracle › › › › › › oracle-database › 19 › sqlrf › NULLIF.html
SQL Language Reference
July 15, 2025 - Appendix C in Oracle Database Globalization Support Guide for the collation determination rules, which define the collation NULLIF uses to compare characters from expr1 with characters from expr2, and for the collation derivation rules, which define the collation assigned to the return value of this function when it is a character value ... The following example selects those employees from the sample schema hr who have changed jobs since they were hired, as indicated by a job_id in the job_history table different from the current job_id in the employees table:
DotFactory
dofactory.com › sql › nullif
SQL NULLIF Function
SELECT NULLIF('SQL', 'NoSQL') AS NotEqual, NULLIF('SQL', 'SQL') AS Equal Try it live
Hightouch
hightouch.com › sql-dictionary › sql-nullif
SQL NULLIF - Syntax, Use Cases, and Examples | Hightouch
December 29, 2023 - This result includes product names, but it replaces 'Discontinued' with NULL using the NULLIF function. Replacing specific values with NULL in query results. Suppressing or hiding data based on specific conditions. Handling equality as a distinct case. The SQL NULLIF function is a standard SQL feature and is available in most relational database management systems (RDBMS) that support SQL.
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 …
EDUCBA
educba.com › home › data science › data science tutorials › sql tutorial › sql nullif()
SQL NULLIF() | A Quick Glance to SQL NULLIF() with Examples
March 10, 2023 - SELECT AVG(COALESCE(NULLIF(sales_target,sales_current),0.00)) AS 'Avg target to be achieved' FROM sales; In the above example, we have first used NULLIF to return a null value if the salesperson has completed his or her targets and return ...
Call +917738666252
Address Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
SQL Tutorial
sqltutorial.org › home › sql nullif function
SQL NULLIF Function
February 8, 2025 - The NULLIF function is equivalent to the following searched CASE expression: CASE WHEN value1 = value1 THEN NULL ELSE value1 ENDCode language: SQL (Structured Query Language) (sql) The following example uses the NULLIF function with two arguments are 100:
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] | --------+--------+-------------+ Copy · Snowflake Python APIs · Snowflake REST APIs · Snowflake CLI · See all interfaces · On this page · Syntax · Arguments · Returns · Collation details · Examples ·
Javatpoint
javatpoint.com › sql-server-nullif
SQL Server NULLIF - javatpoint
SQL Server NULLIF with sql server, install visual studio, install sql server, architecture, management studio, data types, db operations, login database, create database, select database, drop database, create table, delete tabel, update table, min function, max function, sum function, sql ...
Reddit
reddit.com › r/sql › can someone give me a real world example of the nullif function? i know that it’s supposed to return a bull if the two expressions are equal but i can’t think of a real world scenario where i would use this function.
r/SQL on Reddit: Can someone give me a real world example of the NULLIF function? I know that it’s supposed to return a Bull if the two expressions are equal but I can’t think of a real world scenario where I would use this function.
January 10, 2022 -
Thanks!
Meant Null* not Bull. Apologies.
Top answer 1 of 5
11
This is the main "real world" use: select 1/nullif(foo,0) as foo_inverse Wrapping your divisors in nullif keeps your query from erroring out due to divde by zero. If you want some default value (say X) instead of null as a result, then wrap the whole thing in a nvl(). select nvl(1/nullif(foo,0),X) as foo_inverse
2 of 5
8
I use it a lot because the software I work with typically does not set values to NULL when a user removes a value from a record. It will often set the value to an empty string which I then have to treat the same way as a NULL. Most of my NULL checks look like COALESCE(NULLIF(foo, ''),bar).
DB Vis
dbvis.com › thetable › postgresql-nullif-conditional-logic-made-easier
PostgreSQL NULLIF: Conditional Logic Made Easier
September 11, 2024 - Yes, the NULLIF function can be used in conjunction with any other conditional operator or function. For example, it is often used within CASE expressions to handle specific conditions and return appropriate results. PostgreSQL NULLIF is a standard SQL function that returns NULL if two arguments ...
Database Guide
database.guide › how-nullif-works-in-sql-server
How NULLIF() Works in SQL Server
In SQL Server, the NULLIF() expression checks the value of two specified expressions. It returns a null value if they’re equal, otherwise it returns the first expression. ... Here, both expressions are equal, and so the result is a null value. Here’s what happens when the expressions are not equal: ... This time the first value is returned. Here’s an example ...
W3Schools
w3schools.com › sql › sql_isnull.asp
SQL IFNULL(), ISNULL(), COALESCE(), and NVL() Functions
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...