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

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!

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

select

sum(sales) from

k_sales

where year_id=?Process_year

Regards
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 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

!

Raja K Thaw
My wiki: http://en.wikipedia.org/wiki/User:Kt_raj1
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.
 
HTH!
 

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

You must sign in to leave a comment.