In SQL, ISNULL function is used to replace NULL values with a specified alternative value.
ISNULL(expression, replacement_value)
• Specify the 'expression/value' to be checked for NULL.
• Specify the replacement_value to replace the NULL with if the value is NULL.
1. Let's assume we have a table named "[Employees]".
2. Let's assume you want to replace any NULL values in the Salary column with the value '5000'.
3. Run below SQL statement :
SELECT *, ISNULL(Salary, '5000') AS [Salary2] FROM [Employees];
4. In above statement, ISNULL function replaces all NULL values within the Salary column with the value '5000'.
Using this function in a select statement won't modify the [Employees] table directly, but it will only be reflected in the select statement's output.
The Isnull function in SQL checks if a value is NULL or not.
To check for NULL values in SQL, use the "IS NULL" condition in your query.
To set a NULL value in SQL, simply assign NULL to the column or variable.
Use the Isnull function to handle NULL values and the Max function to find the maximum value in SQL queries.