sql - Is there a way to have a placeholder when select returns no rows? -


i have table, report_total, contains calculated values of total_types_cd (codes) not of them.

if there no corresponding row, i'd have placeholder in select such renamed total_amt (unitem_cntrib/total_contrib...) has value of 0 , return of 8 items if no values found. thought maybe coalesce function might work have not been able write query acceptable.

these query results going pdf report , want something, if 0. right now, no report getting generated because select returns no row if all values not present. below select statement , $p{reportid} input report generator.

select  unitem_cntrib, total_cntrib, unitem_expnd, total_expnd,         unitem_pldg, on_hand, tot_loan, unitem_loan (select total_amt  report_total calculation_type_cd ='unitemized_plus_lumpsum'  , total_type_cd = 'tot_cntrb' , report_info_id=$p{reportid} )  unitem_cntrib, (select total_amt report_total calculation_type_cd ='grandtotal'  , total_type_cd = 'tot_cntrb' , report_info_id=$p{reportid} )  total_cntrib, (select total_amt report_total calculation_type_cd ='unitemized_plus_lumpsum'  , total_type_cd = 'tot_expnd' , report_info_id=$p{reportid} )  unitem_expnd, (select total_amt report_total calculation_type_cd ='grandtotal'  , total_type_cd = 'tot_expnd' , report_info_id=$p{reportid} )  total_expnd, (select total_amt report_total calculation_type_cd ='unitemized_plus_lumpsum'  , total_type_cd = 'tot_pledge' , report_info_id=$p{reportid} )  unitem_pldg, (select total_amt report_total calculation_type_cd ='lumpsum'  , total_type_cd = 'tot_cntrb_balance' , report_info_id=$p{reportid} )  on_hand, (select total_amt  report_total calculation_type_cd ='lumpsum'  , total_type_cd = 'tot_loan_principal' , report_info_id=$p{reportid} )  tot_loan, (select total_amt  report_total calculation_type_cd ='unitemized_plus_lumpsum'  , total_type_cd = 'tot_loan' , report_info_id=$p{reportid} )  unitem_loan 

i think want conditional aggregation:

select max(case when calculation_type_cd = 'unitemized_plus_lumpsum' , total_type_cd = 'tot_cntrb'                  total_amt end) unitem_cntrib,        max(case when calculation_type_cd = 'grandtotal' , total_type_cd = 'tot_cntrb'                  total_amt end) total_cntrib,        . . .  report_total rt rt.report_info_id = $p{reportid}; 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -