Using ISNULL() function
The ISNULL()
function is used to return the defined input value in case the passed-in expression has NULL
as its value. It only accepts two parameters and only evaluates the passed-in expression. We will walk through a few simple examples of it and do a comparison between ISNULL()
and COALESCE()
in this section.
How to use ISNULL()
Let’s jump into the examples!
Run the following code in SSMS:
SELECT ISNULL('Hello', 'World') AS [Output]
The result returned is as follows:
Figure 4.14 – Result of the query
As we can see, when we pass in two VARCHAR
values, the function evaluates the first one (in this case, Hello
) and determines it is not a NULL
value, so it returns the Hello
value itself as result.
Now, run the following chunk of code:
SELECT ISNULL(NULL, 'World') AS [Output]
The result we get this time is as follows:
Figure 4.15 –...