If you are on IBM iSeries 6.1, then you can you can use the new values statement as I demonstrate below with SQL pocedural language:
DECLARE v1 int;
SET string1= 'VALUES(SELECT COUNT(*) from MyTable) INTO ?';
PREPARE s1 from string1;
EXECUTE s1 using v1;
The solution is more complicated if you are on a release prior to 6.1 since you need to declare a cursor using dynamic SQL.
DECLARE C1 CURSOR FOR S1 ;
SET STRING2 = 'SELECT COUNT(*) FROM MyTable' ;
PREPARE S1 FROM STRING2 ;
OPEN C1 ;
FETCH C1 INTO V1 ;
|