All Forums General
Maria911 1 post Joined 02/14
10 Feb 2014
parametrics query

Hi, everyone. I'm new in Teradata and SQL
Please, could you write me  an example of script with parameter. I coudn't find information how to write query.
For clear understandind what i mean:
Simple script

sum(sales) from
where year_id=2012

I nead something like this

sum(sales) from
where year_id=a

How will it be right in Teradata?  Thank you!

Renji 17 posts Joined 08/05
11 Feb 2014

If you are running in SQL Assistant, you can have parameters in your SQL and the values can be assigned at run tme. You need to do a ?variable as below. When you run the query, it will ask you for the value. If you are running this thru a batch script, like Unix or something, there are ways to pass parameters to the SQL


sum(sales) from


where year_id=?Process_year

John Abraham

Raja_KT 1246 posts Joined 07/09
11 Feb 2014

You can parameterize with many stuffs in unix or linux like below (say ksh file):

export DB_NAME=dd01




export LOG_FILENAME=$HOME/raja.log

bteq<<! >>${LOG_FILENAME} 2>&1



.run file $HOME/abc.sql



Raja K Thaw
My wiki:
Street Children suffer not by their fault. We can help them if we want.

Adeel Chaudhry 773 posts Joined 04/08
14 Feb 2014

You can use parameters in multiple ways .... using a USING clause, using Macro or using Stored-Procedures.
But there isn't any way to use a variable like you wrote in your example, its kind off a C/C++ style variable .... which isnt as same as SQL style.

-- If you are stuck at something .... consider it an opportunity to think anew.

You must sign in to leave a comment.