parametrics query

General

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

select
sum(sales) from
k_sales
where year_id=2012

I nead something like this

a:=2012
select
sum(sales) from
k_sales
where year_id=a

How will it be right in Teradata?  Thank you!

3 REPLIES
Enthusiast

Re: parametrics query

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

select

sum(sales) from

k_sales

where year_id=?Process_year

Enthusiast

Re: parametrics query

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

export DB_NAME=dd01

export DB_USER_NAME=BATCH_1

DB_PASSWORD=xyz

export LOG_FILENAME=$HOME/raja.log

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

.logon ${DB_NAME}/${DB_USER_NAME},${DB_PASSWORD}

.run file $HOME/abc.sql

.quit

!

Teradata Employee

Re: parametrics query

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.

HTH!