cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How can I insert the result set of a procedure into a table (V8)?

VolkerBarth
Contributor
6,097

Having written stored procedures for V8 (and below) for years, it's somewhat embarrassing that I'm stuck on this question:

Whereas V9 and above have the handy "SELECT FROM myProcedure()" syntax, V8 has not.

So, within a different stored procedure, when I have a stored procedure myProcedure that returns a result set and I want to insert the result set into a table (here a local temporary one), do I have to use a cursor loop in V8?

I.e. if MyProcedure returns a result set with column MyPk, is a cursor loop like the following the single approach:

begin
   declare local temporary table LT (pk int not null primary key);
   for forCrs as crs
      cursor for call Myprocedure()
      -- for read only -- correction: Not allowed (and not necessary) with call
   do  
      insert LT values(MyPk);
   end loop;
   -- do something with LT's contents   
end;

Sidenote: T-SQL has the INSERT ... EXEC syntax for that but that doesn't seem to work with V8, and it would be infeasible here as I'm dealiung with a Watcom-SQL procedure (of course!).

Accepted Solutions (0)

Answers (0)