Page 1 of 1

How can u retrieve the null values in a field?

PostPosted: Mon Dec 13, 2010 12:21 pm
by ragur.satheesh
How can u retrieve the null values in a field?

Re: How can u retrieve the null values in a field?

PostPosted: Mon Dec 13, 2010 2:13 pm
by GuyC
null-indicator variables

Re: How can u retrieve the null values in a field?

PostPosted: Thu Dec 23, 2010 2:03 pm
by Selvaraj
Code dis query select * from table where column is null

Re: How can u retrieve the null values in a field?

PostPosted: Fri Dec 24, 2010 1:25 am
by dick scherrer
Hello,

Keep in mind that you can determine if a column is NULL using the null-indicator variable -but also keep in mind that there is No Such Thing as a NULL VALUE in the column. . .

Re: How can u retrieve the null values in a field?

PostPosted: Wed Dec 29, 2010 3:32 pm
by chandrababun
MOVE ZEROES   TO WS-LASTNAME-IND

   EXEC SQL
      SELECT LASTNAME
        INTO :WS-LAST :WS-LASTNAME-IND
        FROM  EMPLOYEE
       WHERE  EMPNO = :WS-EMPNO
   END-EXEC.
   IF WS-LASTNAME-IND < ZEROES
      .....
   END-IF.


WS-LASTNAME-IND --- Need to define the null indicator variable with s9(04) comp in Working storage

We can test the indicator variable WS-LASTNAME-IND for a negative value. If it is negative, the corresponding value in the host variable WS-LAST is NULL, and therefore, the contents of WS-LAST can be disregarded.

It is not necessary to initialize the WS-LASTNAME-IND before the SQL statement. DB2 will place a negative value or zero based on the contents of the column (NULL or NOT). But it is good programming practice to initialize all host variables and indicator variables.

If the indicator variable is not specified and a NULL value is returned, DB2 will flag an error condition and the value in the WS-LAST column is undefined and unpredictable.