skmathur
skmathur

Reputation: 1627

User-Defined variable in query teradata

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

Upvotes: 1

Views: 24345

Answers (1)

Eric Falkenberg
Eric Falkenberg

Reputation: 69

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

Upvotes: 2

Related Questions