sql - Count Returning blank instead of 0 -


good day here code

select      'expired item -'+ datename(mm,dateadd(mm,4,ae.fld_loan)) [month]     ,count(pit.fld_id)'count'     ,sum (pit.fld_gram)'grams'     ,sum (ph.fld_amnt)'principal'  #allexpired ae     inner join transactions.tbl_item pit     on ae.fld_mainid=pit.fld_mainid     inner join transactions.tbl_histo ph     on ae.fld_mainid =ph.fld_mainid group datename(mm,(dateadd(mm,4,ae.fld_loan))) 

the problem i'm facing count function not return 0 if has no values, sum function not return null if there no resulting values retrieved, instead output blank, why so? , how can fix it?

here screen shot of sample output

a

ofcourse not want want output 0 , nulls. please me not know whats wrong. thank you.

you cannot expect records outputted when using group clause, when no records exist in source.

if want output of 0 sum , count functions, should not use group by.

the reason when have no records, group clause have nothing group by, , not able give output.

for example:

select count(*) (select 'dummy' [dummy] 1 = 0) dummytable 

will return 1 record value '0', as:

select count(*) (select 'dummy' [dummy] 1 = 0) dummytable group [dummy] 

will return no records.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -