Previous Topic: Displaying an SQL Column with Data Type BINARYNext Topic: Handling Null Values at Total Time


How to Test and Display Null Values

The sales table below contains daily sales data for specific products.

Table Definition

CREATE TABLE INV.SALES
(PRODUCT       CHAR(20) NOT NULL,
 SALES_DATE    DATE     NOT NULL,
 UNITS_SOLD    INTEGER);

Notice that the UNITS_SOLD field may contain null values. A null value means "We don't know how many units we sold". That is much different than the value zero which means "We didn't sell any product on this date".

Here's how to create a detail report that displays null values on the detail line.

Detail Report

col. 2
▼
IN  DB(Q)  DICTIONARY=TSTDICT   SCHEMA=INV
SQL SELECT * FROM SALES;
01OUT 80  D
0151*001  PRODUCT      HF
0151*002  SALES_DATE   HF
0151*003  UNITS_SOLD   SZ=6   F-   HF
0152*001  PRODUCT
0152*002  SALES_DATE
0152*003  '---null---'
017       IF UNITS_SOLD_NULL_IND = -1    200
017100    TAKE 1
017200    TAKE 2

The UNITS_SOLD_NULL_IND will be set to minus one to indicate a null value. A zero value indicates that UNITS_SOLD is not null.

Report Output

       PRODUCT               SALES_DATE           UNITS_SOLD   WASHING MACHINES           yyyy-mm-dd                14   Washing Machines           yyyy-mm-dd          ───null---   WASHING MACHINES           yyyy-mm-dd                 0   WASHING MACHINES           yyyy-mm-dd                 3   WASHING MACHINES           yyyy-mm-dd                12