tags:

views:

210

answers:

1

I have a situation in BIRT reporting. A report I created is insisting on displaying some fields as blank rather than zero. The situation arises when the field is actually a sub-select that returns no rows.

So for example, if the select includes:

0 as p3,

then the 0 is displayed okay. If however, the select has:

(select sum(other_field) from other_table where ...) as p3,

the field is displaying blank.

Modifying the data so that rows exist for the sub-select results in a value being displayed, even if their resultant value is zero.

So I'm thinking that somehow BIRT is treating a sub-select returning zero rows as a NULL (which it also displays as an empty cell) rather than a zero. Does anyone have any idea how to coerce BIRT into displaying an actual 0 rather than an empty cell?

I'm using DB2/z v8 if anyone needs to post a DBMS-specific answer, although even suggestions based on other vendors would be appreciated.

+3  A: 

Try using the COALESCE function to force a value when a column or expression might return NULL.

COALESCE((select sum(other_field) from other_table where ...), 0) as p3,
Fred Sobotka
Brilliant! That worked perfectly.
paxdiablo