In
this article I am going to explain how to show 0 instead of null value in sql
server.
In
previous article I have explained COALESCE function of sql server with example,
Sql Server’s CASE expression and how to find difference between two dates inday, hour, minute and second using 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
Read
this article: COALESCE function of sql server with example.
Example:
Select id,Name,Phone, COALESCE(salary,0) as [Salary] from
Employee
No comments:
Post a Comment