HomeSQL ServerHow to replace NULL values with alternate values in SQL Server ?

How to replace NULL values with alternate values in SQL Server ?

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

image

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

When dealing with a relational database management system (RDBMS) like SQL Server, compatibility level is an important concept to understand....
In this blog post, let’s learn about the error message “49975 – Unable to load controller client certificate due to...
In this blog post, let’s learn about the error message “49973 – Cannot remove tempdb remote file to local tempdb...