NULLIF function in SQL Server

Published on August 26, 2016 by abundantcode

Filed under SQL Server

Last modified August 26, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 413 times

The NULLIF function in SQL Server returns a NULL value if the two input expressions return the same value else the first value (expression) is returned.

For example , assume that you want to compare two columns (Address1 and Address2) in the Address table and want to return NULL if both are same to indicate there is NO change and if the addresses are different to use the first one , we could use the NULLIF in the query.

Use AdventureWorks2014
SELECT  AddressId,AddressLine1,AddressLine2,
  FROM [AdventureWorks2014].[Person].[Address]
  ORDER BY AddressID 


If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


You might be Interested in these Posts

How to Perform Inner Join using LINQ in C# ?

Are you looking for the syntax on how to perform inner join using LINQ in C# ? . Below is a sample c...

How to hide the status bar in Microsoft Excel with the VBA Code?

Do you want to hide the status bar in Microsoft Excel ?. You can use the VBA code to do it quickly. ...

Displaying all the worksheet names in Excel using VBA Code

Do you want to display the names of the worksheets in the excel workbook ?. Here;s how you can do it...