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 ifexpression
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 |
Namecolumn, you can use the following query:
SELECT ID, ISNULL(Name, 'Unknown') FROM TableName;
#Name | |
---|---|
John Smith | |
Unknown |
Note:
is NULL, the ISNULL function returns the
expressionitself 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!