By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
How do I overcome this error and execute the code dynamically?
d mycount s 10p 0 c eval string = 'select count(*) into : mycount from MyTable' * c/exec-sql c+ prepare S1 from string c/end-sql * c/exec-sql c+ execute S1 c/end-sql
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 v1 int; SET string1= 'VALUES(SELECT COUNT(*) from MyTable) INTO ?'; PREPARE s1 from string1; EXECUTE s1 using v1;
DECLARE C1 CURSOR FOR S1 ; SET STRING2 = 'SELECT COUNT(*) FROM MyTable' ; PREPARE S1 FROM STRING2 ; OPEN C1 ; FETCH C1 INTO V1 ;
Dig Deeper on DB2 UDB (universal databases)
Related Q&A from Kent Milligan
Create a host variable of the where in statement on the fly with dynamic SQL.continue reading
When working with DB2 files with columns that have both short and long names, there is no option choose which column names are returned via ODBC ...continue reading
When developing tables in a parent-child relationship, use a primary key and a foreign key along with a unique ID to make your database easier to ...continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.