05 October 2016 Sudhanshu Ranjan 731

NULLIF Function in SQL Server with example

Description

Most of the interviewer ask this question. What is NULLIF Function? The NULLIF function compares expression1 and expression2. If expression1 and expression2 are equal, the NULLIF function returns NULL. Otherwise, it returns the first expression which is expression1.

Expression1 and Expression2 should be same datatype.

Example

SELECT NULLIF(8, 8); -- Return NULL

SELECT NULLIF(8, 9); -- Return 8 (Ther first expression)

SELECT NULLIF('DOTNETCUBE',8); -- This query gives error because exp1 and exp2 have diffrent datatype.

SELECT NULLIF('DOTNETCUBE','DOTNETCUBE'); -- Return NULL

You can share at :

About Author
Sudhanshu Kumar Ranjan | Lead Engineer at HCL Technologies | Expertise in Microsoft Technology | Author | Blogger | Programmer
Know More
Connect with him on Facebook | Google+ | LinkedIn | Twitter

Recommended Post

Leave a comment

About Dotnet Cube

It's my blog - Dotnet Cube, where you will learn and get solutions about programming, web designing and development. I started this website to share my knowledge and experience which might help someone.

You can get more details about me and my blog at About Us page.

Subscribe Newsletter

Subscribe to our monthly newsletter to get the latest industry news, Media Group updates and our current specials.

Follow On Us...

Home | About | Advertise | Copyrights | Privacy | Contact | Admin

Copyrights © 2015-2017 dotnetcube.com. All rights reserved