The ISNULL function in SQL checks whether a value is NULL and returns the specified value (if the value is NULL) or the original value (if the value is non-NULL). Its syntax is: ISNULL(expression, replacement_value). This function is used to replace NULL values to improve readability, prevent errors, and handle NULL values in aggregate functions.
Usage of ISNULL function in SQL
What is the ISNULL function?
The ISNULL function is a SQL function that checks whether a value is NULL and returns a specified value if the value is NULL or the original value if the value is non-NULL.
Syntax:
ISNULL(expression, replacement_value)
Among them:
expression
: The value to check. replacement_value
: The value returned if expression
is NULL. Usage:
The ISNULL function can be used in various situations, for example:
Example:
Consider the following table:
ID | Name |
---|---|
1 | John Smith |
NULL |
Name column, you can use the following query:
<code class="sql">SELECT ID, ISNULL(Name, 'Unknown') FROM TableName;</code>
#Name | |
---|---|
John Smith | |
Unknown |
Note:
is NULL, the ISNULL function returns the
expression itself without replacement.
The above is the detailed content of Usage of isnull in sql. For more information, please follow other related articles on the PHP Chinese website!