How to replace null value with 0 in sql server

In this article I am going to explain how to replace null value with 0 in sql server.

Description:
We have three methods to show 0 instead of null value in Sql.

Method 1: ISNULL
Example:
Select id,Name,Phone, ISNULL(salary,0) as [Salary] from Employee

Method 2: CASE
Example:
Select id,Name,Phone, case when salary IS NULL then 0 else salary end as [Salary] from Employee
  
Method 3: COALESCE
Example:
Select id,Name,Phone, COALESCE(salary,0) as [Salary] from Employee





Post a Comment

0 Comments