I would like to do some select queries within a stored procedure and store the output to a volatile table. I am not clear on the owernship and scope of the volatile tables. I have run into some errors. Here is an example stored procedure to pull ages.
--Example: Stored Procedure to pull ages. replace Procedure database.tmpAge ( IN tblSearchCohort varchar(300) not cs, IN tblOUTPUT varchar(300) not cs) begin --Would like to put a validation check for tmpBirthday here.... SET DYNASQL1 = ' create volatile table tmpBirthday as ( SELECT id, birthday FROM ' || tblSearchCohort || ' as A INNER JOIN SourceTable as B on A.id = B.id ) with date primary index (id) on commit preserve rows; ' CALL DBC.SysExecSQL( DYNASQL1 ); SET DYNASQL2 = ' create volatile table ' || tblOUTPUT || ' as ( SELECT id, cast( cast(birthday - indexdate as decimal(18,3) / 365.250 as INT ) as age FROM ' || tblSearchCohort || ' as A INNER JOIN tblBirthday as B on A.id = B.id ) with date primary index (id) on commit preserve rows; ' CALL DBC.SysExecSQL( DYNASQL2 ) DROP TABLE tmpBirthday; END;
1. I would like to check the DBC/spool to see whether the table names already exist and send a message that the procedure can't run until the drop conflicting table names. In the above example, I would like to instantiate a volatile table called "tmpBirthday" as an interim step, use it for computation and potentially drop it before the procedure ends. If the user already has a table tmpBirthday, send a flag that the tmpAge procedure cannot run.
2. I am also running into 'concurrent change conflicts' when users send in table specifications for volatile tables for the tblSearchCohort. These are not consistent.
The above example was written on the fly, so there may be some minor inconsistencies. I realize I don't need the interim table for this particular usage, but I will for other SP I have planned.