Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 25 Oct 2002 @ 22:34:48 GMT


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


Subj:   Variables as Table Name(s) in Stored Procedure
 
From:   Anomy Anom

<-- Anonymously Posted: Friday, October 25, 2002 17:38 -->

Hi all,

As a part of a bigger Stored Procedure there are a couple of tables I'd like to run an Insert statement against. This Insert is 99% the same for each table, the differences being the Table Name and some condition in the Where clause.

So, I'm thinking that I can use the Procedure to run this Insert one time for each table, while using variables to swap in the differences. The Where clause swap I've got, but I'm running into trouble changing the Table Name for the Insert.

Here's a quick example, using tables TableOne, and TableTwo :

CREATE PROCEDURE TestStProc (IN tblName CHAR(8), IN criteria CHAR(1) )
BEGIN
  INSERT INTO :tblName
  SELECT * FROM some_table
  WHERE Code = :criteria;
END;

I know it's wrong, because I get a compile time syntax error at the 'INTO:'. So, is there any way to use variables as Table Names? Should I use a different approach?

Gracias!



     
  <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