Previous Topic Next topic Print topic


Non-Select SQL Statements

When non-SELECT statements are issued dynamically, the coding task is relatively easy because there is no need to dynamically allocate main storage.

To issue a non-SELECT statement dynamically:

  1. (Optional) Test each SQL statement using the SQLWizard (Windows) or Interactive SQL (UNIX) to see that proper results are obtained.
  2. Load the SQL statement into a data area.
  3. Issue a PREPARE and then an EXECUTE (or EXECUTE IMMEDIATE) statement.

    Be sure to handle any errors that result.

The following example executes an UPDATE statement that gives every employee a 10 percent raise:

     MOVE 'update employee set payrate=payrate*1.10' 
                                                TO SQLCMD
     EXEC SQL 
         EXECUTE IMMEDIATE :sqlcmd 
     END-EXEC 
     ...
Previous Topic Next topic Print topic