Progress
Embedded SQL-92
Guide and Reference


Use Indicator Variables

You can use indicator variables to insert NULL values into a column. Set the indicator variable for a particular column to negative one ( -1 ) and use the indicator variable along with the associated host variable in the value list of the INSERT statement.

EXAMPLE

The following example shows how to insert NULL values for the commission and projno columns in the employee table using indicator variables:

/*
** Declare section for host variables and indicator variables>
*/
EXEC SQL BEGIN DECLARE SECTION ;
   .
   .
   .
EXEC SQL END DECLARE SECTION ;
   .
   .
   .
empno_v = 2402 ;
strcpy (ename_v, ’RALPH’) ;
strcpy (job_v, ’CLERK’) ;
strcpy (hiredate_v, ’02/02/1999’) ;
sal_v = 2000 ;
commission_i = -1 ;
deptno_v = 10 ;
projno_i = 1 ;   .
   
EXEC SQL
     INSERT INTO employee
     VALUES (:empno_v, :ename_v, :job_v, :hiredate_v,
             :sal_v, :commission_v INDICATOR :commission_i,
             :deptno_v, :projno_v:projno_i) ; 

This example illustrates setting the indicator variable to negative one ( -1), rather than placing the NULL keyword in the INSERT statement. The program then inserts a NULL value, not the value in the host variable.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095