Sunday, March 5, 2017

Sql server : Show 0 instead of null value

In this article I am going to explain how to show 0 instead of null value in sql server.


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

1st alternate: ISNULL
Sql’s Isnull function is used to replace null with specified replacement value.

Syntax:
isnull(column_name,specified_value)

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

2nd alternate: CASE
Check this article : CASE expression in Sql Server.

Example:
Select id,Name,Phone, case when salary IS NULL then 0 else salary end as [Salary] from Employee
  
3rd alternate: COALESCE

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




No comments:

Post a Comment