COALESCE function can be used in a similar manner to the ISNULL function.
COALESCE function replaces the NULL value in the columns to an alternative value specified.
Below is shown the "Customers" 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 COALESCE Function Example
Type or Copy the SQL into the Text Editor, click the "View Result" button, to see the result.
In the below SQL the COALESCE function replaces the NULL value in the Address columns with "NO DATA".
Select FirstName, LastName, COALESCE(Address,'NO DATA') as Address1
from Authors;
In the below SQL the COALESCE function replaces the NULL value in the City column with "NO DATA".
Select FirstName, LastName, COALESCE(City,'NO DATA') as City1
from Authors;
SQL in Text Editor: