1

I want to run a similar query at different times changing only one thing in the where clause and the table name that it's pulling from.

declare ?tablename varchar(100);
set ?tablename = 'some_table_this_time';

declare ?id int;
set ?id = 12

select * from ?tablename
where my_id = ?id

This syntax does not work in teradata. I've used the @variable syntax in other sql programs, but cannot find the correct way in teradata.

Research:

http://forums.teradata.com/forum/database/using-parameters-with-queries

How to use variables in Teradata SQL Macros

Community
  • 1
  • 1
skmathur
  • 1,587
  • 5
  • 14
  • 21
  • possible duplicate of: [this](http://stackoverflow.com/questions/13895370/how-to-execute-dynamic-sql-in-teradata) – Beth Aug 27 '14 at 20:50
  • 1
    Most DBMSes (including Teradata) don't support table names passed as a variable outside of Dynamic SQL. If you're using SQL Assistant you can simply run **select * from ?tablename where my_id = ?id** as-is and it will prompt for both variables. – dnoeth Aug 27 '14 at 20:57

1 Answers1

2

There isn't a direct equivalent to that syntax in Teradata. Check out this blog post by Dieter for an interesting example of how to do something similar though:

http://developer.teradata.com/blog/dnoeth/2011/03/global-and-session-level-parameters-in-sql