Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 14 Aug 2002 @ 15:08:07 GMT


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


Subj:   Re: Prepare SQL in stored procedures
 
From:   Michael Larkins

Hi Larry:

I am not sure if you are really "creating" SQL as much as this example implies, simply passing a value for substitution. If I am interpretting this correctly, you do not need a stored procedure (SP); a macro will work fine. A Macro can return rows where an SP can only return individual values in parameters.

A macro to do this:

CREATE MACRO  My_Query   (simno char(10)) AS
(Select sim_mfr_no from valid_mfr where sim_mfr_no = :simno ;);

Exec My_Query ('');

or

USING simno char(10))
Exec My_Query (:simno);
/*  this technique is normally used when reading simno from disk file */

You are receiving an error on your SP because there is no "Prepare" command in stored procedural language(SPL). You simply put your SQL into a SP along with the appropriate SPL (you can do dynamic substitution in an SP like in a macro). Additionally, each select must reference a column in the WHERE that is defined as a UPI or USI to select only one row. If more than one row is expected, you must build a FOR/END FOR loop into the SP to process each row individually from SPOOL using a cursor.

I hope this helps you accomplish your task.

Mike



     
  <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: 15 Jun 2023