ISNULL function is used in SQL statements for the columns that allow NULL values in the database tables.
ISNULL function acts on the NULL values of the column by providing an alternate value that is specified in the function.
Below is shown the "Authors" table:
White |
Michael |
22 Cleveland Av. #24 |
Berkeley |
Hunter |
Sheryl |
NULL |
Salt Lake City |
Smith |
Charlene |
NULL |
San Francisco |
Jhonson |
Fernandis |
2286 Cram Pl. #81 |
NULL |
Robert |
Paul |
1976 Arlington Pl. |
NULL |
SQL ISNULL Function Example
The below query replaces the NULL value with the given alternate value where the column is NULL.
The alternate value can be either a string value or numeric value correspondingly.
Usually for calculation purposes we replace NULL values with zero.
Text Editor below has the SQL Query, click the "View Result" button, to see the result.
The below example shows replacement of NULL values in Address and City columns with "No Address" and "No City" correspondingly.
Select FirstName, LastName, ISNULL(Address,'No Address') as Address1,ISNULL(City,'No City') as City1
From Authors;
SQL in Text Editor: