Assume a scenario where you are trying to get the records from the table where some of the records contains NULL column values and you would like to replace it with an alternate value.
How to replace NULL values with alternate values in SQL Server ?
Use ISNULL method which accepts two parameters
– column name (value)
– alternate value if the value is NULL
The ISNULL method simply checks if the specified expression is NULL and if this is true it replaces the NULL value with the alternate value. The return type value (second parameter) should be of the same type as the first parameter.
Here’s an example of the usage of the ISNULL method.
SELECT JobTitle, OrganizationLevel = ISNULL(CAST(OrganizationLevel as varchar(200)),'-- No Top Level Found--') FROM HumanResources.Employee