Method 1 examples

The following two examples demonstrate using method 1, execute immediate. The first example prompts the user to enter a statement and then executes it:

 exec sql begin declare section end-exec 
 01  CMD-1              PIC X(50). 
 01  SRC-COND           PIC X(50). 
 01  SQLSTR1            PIC X(200). 
 exec sql end declare section end-exec 
 
 DISPLAY "ENTER statement". 
 ACCEPT SQLSTR1. 
 exec sql execute immediate :SQLSTR1 end-exec.

The next example prompts the user to enter a search condition to specify rows in the titles table to update. Then, it concatenates the search condition to an update statement and sends the complete statement to Adaptive Server Enterprise.


 MOVE "UPDATE titles SET price = price*1.10 WHERE " 
      TO CMD-1. 
 DISPLAY "ENTER SEARCH CONDITION:". 
 ACCEPT SRC-COND. 
 STRING CMD-1 delimited by size SRC-COND DELIMITED BY
 SIZE INTO SQLSTR1. 
 exec sql execute immediate :SQLSTR1 end-exec.