Subject Who to check NULL value in a query if sub query is writting NULL values.
Author jyotindra_bhoyania
hi...

i have written query like
select (select sum(val1) from table_y where item='A' and
emp_id=x.emp_id) -(select sum(val1)from table_y where item='D' and
emp_id=x.emp_id) from table_x x.

in my table "table_y" does have value with item='A' so it is giving
me value
and
in my table "table_y" does not have any record with item='D' so that
is why it is giving me null value and i am doing substracting value
in above query.
But the whole query is writting null value.
so here i need NVL function like oracle to convert null value
into 0(ZERO).

we have written stored procedure "NVL" to check null value and put it
in the query like
select (select vval from nvl(select sum(val1) from table_y where
item='A' and emp_id=x.emp_id),0) - (select vval from nvl((select sum
(val1)from table_y where item='D' and emp_id=x.emp_id),0) from
table_x x.

OR

We have to write a external function for that..?

What is best way to handle the null value in the query.