SQL Server NULLIF() Function

Posted by

SQL Server

NULLIF()

Function

Example

Compare two expressions:

SELECT NULLIF(25, 25);


Definition and Usage

The NULLIF() function returns NULL if two expressions are equal, otherwise it
returns the first expression.

Syntax

NULLIF(

expr1

,

expr2

)

Parameter Values

Parameter Description

expr1, expr2
Required. The two expressions to be compared

Technical Details

Works in: SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data
Warehouse, Parallel Data Warehouse

More Examples

Example

Compare two expressions:

SELECT NULLIF(‘Hello’, ‘Hello’);

Example

Compare two expressions:

SELECT NULLIF(‘Hello’, ‘world’);

Example

Compare two expressions:

SELECT NULLIF(‘2017-08-25’, ‘2017-08-25’);