All Forums Database
darres90 1 post Joined 04/14
16 Apr 2014
Teradata Studios Create Local Variable

I have a query that I would like to avoid hard coding. Using the following example could you give me the code to create such a variable:

select region
from geography_table
where division = 'Central'

I know in MS SQL Server (T-SQL) you can say "declare @division VARCHAR(20)" and set @division = 'Central' before the query will create the variable, but that doesn't work in Teradata.
Thanks for the help.
 

k1ng 16 posts Joined 06/08
23 Oct 2014

were you able to figure this out? looking to do the same thing

ravimans 54 posts Joined 02/14
29 Oct 2014

Hi Darres,
Can you try like this. I haven't ran this but giving you the sample code snippet.
REPLACE Sample_Proc
(
  REGION VARCHAR(20)
)
BEGIN
DECLARE vDivision VARCHAR(20);
/*OPERATION1*/
SET vDivision= 'Central'
/*OPERATION 2*/

select region

from geography_table

where division = vDivision
/*CALLING THE PROCEDURE*/
CALL Sample_Proc('ABCD');

You must sign in to leave a comment.