Example 7 (Dynamic SQL Inserts by Variable Name)
This example creates a dynamic SQL string to insert data from a variable. Instead of extracting the values, it calls the value by variable name.
PROCEDURE dynamic_sql_example2 ()
BEGIN
DECLARE sql2 VARCHAR DEFAULT
'INSERT INTO /shared/updates(c_varchar) VALUES(';
DECLARE temp CHAR;
FORLOOP:
FOR x AS SELECT Categories.CategoryName
FROM /shared/access/Categories Categories
DO
SET temp = CAST(sql2 || 'x.categoryName)' AS CHAR);
EXECUTE IMMEDIATE temp;
END FOR;
END