How to pass parameters from a unix shell script to a .run file in bteq?

Database
The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.
Enthusiast

How to pass parameters from a unix shell script to a .run file in bteq?

I want to pass the two date parametres in the . run file.

 

ksh -x script.ksh 2016-01-01 2016-01-03

 vi script.ksh

v_sql_load_strt_dt="$1"
v_sql_load_end_dt="$2"

export v_sql_load_strt_dt;
export v_sql_load_end_dt;

bteq <<EOF

 

.LOGON 

sel '${v_sql_load_strt_dt}'; -- Its works here

.RUN FILE file.sql
.if errorcode <> 0 then .exit errorcode

.logoff

 

But does not work in the .RUN file.

 

vi file.sql

sel '${v_sql_load_strt_dt}' - '${v_sql_load_end_dt}';

 

.RUN FILE file.sql
+---------+---------+---------+---------+---------+---------+---------+----
sel '${v_sql_load_strt_dt}' - '${v_sql_load_end_dt}';
*** Failure 3535 A character string failed conversion to a numeric value.
Statement# 1, Info =0
*** Total elapsed time was 1 second.

 

Thanks for your help in advance,

Chirag

 

1 REPLY
Senior Supporter

Re: How to pass parameters from a unix shell script to a .run file in bteq?

you can change the file.sql to a template file like - pseudocode not tested:

 

vi file.tmpl

sel '<<<start_dt>>>' - '<<<end_dt>>>';

 

 

v_sql_load_strt_dt="$1"
v_sql_load_end_dt="$2"

 

export v_sql_load_strt_dt;
export v_sql_load_end_dt;

 

sed "s~<<<start_dt>>>~"${v_sql_load_strt_dt}"~g; s~<<<end_dt>>>~"${v_sql_load_end_dt}"~g; ~g" file.tmpl > file.sql;

bteq <<EOF

 

.LOGON 

sel '${v_sql_load_strt_dt}'; -- Its works here

.RUN FILE file.sql
.if errorcode <> 0 then .exit errorcode

.logoff