title: User-Defined variable in query teradata
body: <p>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. </p>
  
  <pre><code>declare ?tablename varchar(100);
  set ?tablename = 'some_table_this_time';
  
  declare ?id int;
  set ?id = 12
  
  select * from ?tablename
  where my_id = ?id
  </code></pre>
  
  <p>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. </p>
  
  <p>Research: </p>
  
  <p><a href="http://forums.teradata.com/forum/database/using-parameters-with-queries" rel="nofollow noreferrer">http://forums.teradata.com/forum/database/using-parameters-with-queries</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2687819/how-to-use-variables-in-teradata-sql-macros">How to use variables in Teradata SQL Macros</a></p>