Home Page for the TeradataForum
 
https:

Archives of the TeradataForum

Message Posted: Wed, 14 Aug 2002 @ 14:55:58 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Prepare SQL in stored procedures
 
From:   Geoffrey Rommel

  I would like to know if it is possible to prepare an sql statement within a stored procedure.  



According to the manuals, PREPARE is available only in embedded SQL. The following syntax compiles correctly:

Create Procedure mfrtest(simno char(10))
BEGIN
declare my_query varchar(500);
set my_query = 'Select sim_mfr_no from valid_mfr where sim_mfr_no = '''
|| simno || '''';
call DBC.SysExecSQL (:my_query);
End;


When I try to run it, however, I get this error:

*** Failure 5568 mfrtest:SQL statement is not supported within a stored procedure.


I believe this is because stored procedures cannot return result sets; they can only return a single row of values.

If your procedure is fairly simple and you need a result set, you should probably use a macro instead:

Create Macro mfrtest(simno char(10))
as
(Select sim_mfr_no
from valid_mfr
where sim_mfr_no = :simno;
);



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 28 Jun 2020