Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

sql server - Instead of NULL how do I show `0` in result with SELECT statement sql?

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.

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'

Which is giving me output like

Ename    Eid    Eprice    Ecountry
Ana      12     452       India
Bin      33     NULL      India
Cas      11     NULL      India

Now instead of showing NULL how can I show price as 0 ?

What should be mention in SELECT statement to make NULL as 0 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use coalesce():

select  coalesce(Eprice, 0) as Eprice

In SQL Server only, you can save two characters with isnull():

select  isnull(Eprice, 0) as Eprice

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...