NVL in SQL Server

In this post, I’ll explain how to use the NVL function in SQL Server.

NVL is a function available in  Oracle; it receives a value; if this value is NULL, then NVL will return a second argument.

How to use it in SQL Server.

In SQL Server, you have a function with the same behavior called NULLIF. It receives two arguments and returns the second one when the first one is NULL.


You can get the same result using COALESCE. The only difference between COALESCE and NULLIF is COALESCE supports more than a second value; it will take the first, not-null value. If you are working with different SQL dialects in the same project, COALESCE is a better alternative; if you want a ubiquitous language in your queries, several SQL dialects support it.

Gustavo Sánchez

Soy especialista en escribir software de calidad. Mediante el uso de marcos de trabajo, técnicas y automatización de procesos he podido reducir los costes operativos de los sistemas de la empresa. Sistemas confiables y adaptables producen clientes felices.