Sql server : Show 0 instead of null value | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

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




Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget