---
title: "How to Use DB2 NULLIF Function"
description: "NULLIF returns a null value if the two arguments of the function are equal. If the arguments are not equal, NULLIF returns the value of the first argument. https://srinimf.com/2024/06/18/sql-query-to-..."
url: https://srinimf.com/2015/06/08/db2-nullif-scalar-function/
date: 2015-06-08
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2015/06/dandelion-sky-flower-nature-39669.jpeg?fit=1880%2C1253&ssl=1
categories: ["DB2", "SQL"]
tags: ["SQL Functions"]
type: post
lang: en
---

# How to Use DB2 NULLIF Function

NULLIF returns a null value if the two arguments of the function are equal. If the arguments are not equal, NULLIF returns the value of the first argument.

Related[SQL Query to Find NULL and Non-null Percentage of Column](https://srinimf.com/2024/06/18/sql-query-to-find-null-and-non-null-percentage-of-column/)

Related[5 More Frequently Asked DB2 SQL Queries](https://srinimf.com/2015/05/15/5-more-frequently-asked-db2-sql-queries/)

[https://srinimf.com/](https://srinimf.com/)[2015](https://srinimf.com/2014/06/08/evergreen-it-skills-beyond-2015/)/08/20/db2-avg-column-function-best-example/

Example:

NULLIF: Suppose that you [want to](https://srinimf.com/2016/02/09/want-to-excel-in-ims-dc-programming-read-this/) calculate the average earnings of all employees who are eligible to receive a commission. All eligible employees have a commission of greater than 0, and ineligible employees have a value of 0 for commission:

SELECT AVG(SALARY+NULLIF(COMM,0))
AS “AVERAGE EARNINGS”
FROM EMP;The result table looks like this:

AVERAGE EARNINGS
================
35248.8461538

Related[SQL Query: Extracting Employees Sal > Avg Salary](https://srinimf.com/2024/04/06/salavgsal-sql-query-how-to-write-in-pyspark-and-pandas/)

*Ref: IBM*

*Ref: IBM*

Related[SQL Sub-query that Returns Single Value: Best Example](https://srinimf.com/2018/01/21/sub-query-to-return-single-value-example-query/)

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2015%2F06%2F08%2Fdb2-nullif-scalar-function%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2015%2F06%2Fdandelion-sky-flower-nature-39669.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=How%20to%20Use%20DB2%20NULLIF%20Function)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2015/06/08/db2-nullif-scalar-function/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2015/06/08/db2-nullif-scalar-function/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2015/06/08/db2-nullif-scalar-function/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2015/06/08/db2-nullif-scalar-function/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Use%20DB2%20NULLIF%20Function&body=https%3A%2F%2Fsrinimf.com%2F2015%2F06%2F08%2Fdb2-nullif-scalar-function%2F&share=email)
-

### Like this:

Like Loading…
