SQL Tutorial - IsNull Function


IsNull function is a SQL Server function. It replaces a null value with a predefined value found inside the function.

The Null Value


The 'IsNull" function consists of two parameters. If the first parameter evaluates to a NULL value then the second parameter's value defined in the function is returned else first parameter's value is returned.

IsNull Syntax


ISNULL (check_expression ,replacement_value)

As seen above if the check_expression returns a null value, then the null value will be replaced by the replacement value.

IsNull example


Select StudentID,StudentName, ISNULL(Height,165) As StudentHeight from Students

In the above example, we have a 'Students' table which takes in the 'Height' details of each student. Since it is an optional column ie. while entering a students record, this column can be omitted. So while taking the list height of all the students details, we are assumming that all null values of height be replaced by 165.