Hello,
I have just started writing stored procedures for a new DB2 server install, and am having problems with using variables to define field names in a SELECT INTO statement. I want to take a field name out of a "field_name_to_use" column in one table, and use it to select data out of another, something like this:
SET v_statement = 'SELECT MIN(' CONCAT v_source_timestamp_field CONCAT ') INTO v_source_end_time FROM ' CONCAT v_source_table;
PREPARE S1 FROM v_statement;
EXECUTE S1;
where v_source_timestamp_field and v_source_table have been retrieved from another table.
However, this gives me the error:
SQL0104N An unexpected token "V_FIRST_END_TIME" was found following "". Expected tokens may include: "". SQLSTATE=42601
I'm sure there is probably an easy way to do this, but I'm new to this, so if anyone can help I'd be really grateful!
Many thanks,
Ian