2

I am execute below query. there are no data but SQL Nevigator fetch ONE record and this record are show the blank. so i want no fetch any record.

select sum(arrears_edutax) 
  from view_govtax_rpt 
    where trunc(receiptdt) between  '01-Oct-2019' and '14-Oct-2019';

But dont use Group BY function.

enter image description here

Kiran Patil
  • 327
  • 1
  • 11

3 Answers3

0

Quick demonstration about what you need

with w0 as 
(
  select 1 x from dual union
  select 2 from dual
), w1 as
(
   select * from w0 where 1=2
)
select c1 from (
  select sum(x) c1 from w1
)
where c1 is not null

Click here for demo

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
0

Try this query

 select sum(null) c1 from dual where 1=2

No data due to 1=2 but one row result

enter image description here

Marmite Bomber
  • 19,886
  • 4
  • 26
  • 53
0

there are no data but SQL Nevigator fetch ONE record and this record are show the blank. so i want no fetch any record

That's not how aggregate queries work.

An aggregate query with no GROUP BY returns one row. The result is the aggregation applied to the filtered rows. Because you had no rows which matched your criteria the aggregated value is NULL. If you had used a COUNT() function instead you would have got zero.

So, if you really want an empty result set (zero rows) when there's no matching data you can use this trick:

select sum(arrears_edutax) 
from view_govtax_rpt 
where trunc(receiptdt) between  date '2019-10-01' and date '2019-10-14'
having count(*) > 0
;

Incidentally, you should get into the habit of using date literals instead of relying on implicit data conversion.

APC
  • 144,005
  • 19
  • 170
  • 281