我如何使用 SELECT 语句 sql 在结果中显示“0"而不是 NULL? [英] Instead of NULL how do I show `0` in result with SELECT statement sql?
问题描述
我有一个 存储过程
,它给了我一个输出(我将它存储在一个 #temp 表中),我将这个输出传递给另一个 标量函数
.
I have one stored procedure
which is giving me an output (I stored it in a #temp table) and that output I'm passing to another scalar function
.
如何使用 SELECT 语句 sql 在结果中显示 0
而不是 NULL?
Instead of NULL how do I show
0
in result with SELECT statement sql?
例如存储过程有如下选择语句:
For example stored proc is having select statement like follwing :
SELECT Ename , Eid , Eprice , Ecountry from Etable
Where Ecountry = 'India'
哪个给了我这样的输出
Ename Eid Eprice Ecountry
Ana 12 452 India
Bin 33 NULL India
Cas 11 NULL India
现在我如何将价格显示为 0
而不是显示 NULL
?
Now instead of showing NULL
how can I show price as 0
?
SELECT
语句中应该提到什么使 NULL
成为 0
?
What should be mention in SELECT
statement to make NULL
as 0
?
推荐答案
使用 <代码>coalesce():
select coalesce(Eprice, 0) as Eprice
仅在 SQL Server 中,您可以使用 isnull()
:
In SQL Server only, you can save two characters with isnull()
:
select isnull(Eprice, 0) as Eprice
这篇关于我如何使用 SELECT 语句 sql 在结果中显示“0"而不是 NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!