Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Table name in from clause in SP

Status
Not open for further replies.

GeneCampbell

IS-IT--Management
Jun 12, 2002
6
US
I am trying to parse a table name from a field in a teradata table, pass the table name to a variable and use the variable to populate the table name in a select statement.

Is this possible?



create procedure core_proddb_s.table_nme2( in p1 int )
begin
Declare var1 char(50);
select table_name into:var1 from core_workdb.load_parameter where campaign_id=:p1;
insert into core_workdb.opportunity_test
select * from :var1;

End;
 
Hi,
I see from you other post you have found the dynamic SQL syntax.

create procedure core_proddb_s.table_nme3( in p1 char(50), out p2 char(50) )
begin
call DBC.SysExecSql('Select campaign_id from ' || :p1);

End;


Therefore you might want to try it on this query.



create procedure core_proddb_s.table_nme2( in p1 int )
begin
Declare var1 char(50);

select table_name into:var1 from core_workdb.load_parameter where campaign_id=:p1;

call DBC.SysExecSql('insert into core_workdb.opportunity_test ' ||
'select * from ' || :var1 );

End;



As I said in the other post SELECT, by itself, is not allowed but maybe the Insert/Select would be.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top