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
?
We can return 0 for NULL in MySQL with the help of IFNULL() method. The syntax of IFNULL() is as follows. IFNULL(YOUREXPRESSION,0);
SELECT column_names FROM table_name WHERE column_name IS NOT NULL; Query: SELECT * FROM Student WHERE Name IS NOT NULL AND Department IS NOT NULL AND Roll_No IS NOT NULL; To exclude the null values from all the columns we used AND operator.
In SQL Server, NULL value indicates an unavailable or unassigned value. The value NULL does not equal zero (0), nor does it equal a space (' '). Because the NULL value cannot be equal or unequal to any value, you cannot perform any comparison on this value by using operators such as '=' or '<>'.
The ISNULL Function is a built-in function to replace nulls with specified replacement values. To use this function, all you need to do is pass the column name in the first parameter and in the second parameter pass the value with which you want to replace the null value.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With