What is the usage of the ISNULL function in SQL?

The ISNULL function is a function in the SQL language used to determine if an expression is NULL. If the expression is NULL, it returns a specified value; if not, it returns the value of the expression.

The syntax for the ISNULL function is as follows: ISNULL(expression, value)

In this case, expression is the expression to be checked for NULL, and value is the value to be returned when expression is NULL.

For example, let’s say there is a table called Employees with columns for id and name, where the name column allows for null values. The ISNULL function can be used to query the name column and return “Unknown” if the value is NULL, or return the actual name value if it is not.

Choose the id and if the name is not available, label it as ‘Unknown’ for the employees.

This query will return a result set containing two columns, id and name. If the name column is NULL, the value in the name column will be replaced with “Unknown”.

bannerAds