NULLIF() in SQL Server

NULLIF – (Definition by Microsoft) returns NULL if the two expressions are equal and if the expressions are different then returns the first expression.

A simple representation as below:

Select NULLIF(100,100),NULLIF(100,101)

Another way of representing

Case when Expression1 = Expression2 Then NULL Else Expression1 End

It is important to be aware that non-deterministic functions may have an impact since it evaluates two times and returns different values. Eg. NEWID(), RAND() etc.

I’d like to grow my readership. If you enjoyed this blog post, please share it with your friends!

One thought on “NULLIF() in SQL Server”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s