BTEQ script

Tools & Utilities
Fan

BTEQ script

how to append date to export filename in BTEQ script.

ex:
.export file =export_file_name_09092010
Tags (1)
3 REPLIES
Enthusiast

Re: BTEQ script

Hi argun,
If you want to append system current date to the export file then you can create a shell script in unix and using unix date command get the desired date format for file. Below is the example code for that

export ex=run_file_$(date +"%Y%m%d")
bteq << sushil
.logon tdpid/user,password
.export report file=${ex};
select count(*) from dbc.tables;
.export reset
.exit
sushil

If you want to get the date from some table and not use the system date then you can create a shell script and logon to BTEQ twice :( to get the task done. Below is an example code for that

bteq << sushil1
.logon tdpid/user,password
.export report file='mydate.ksh';
select 'export mydatex=run_file_'||cast(brth_dt as date format 'yyyymmdd') (title '')
from sushil.nayak
where brth_dt='1984-10-20';
.export reset
.exit
sushil1
chmod 700 mydate.ksh
. /home/sasuser/sushil/mydate.ksh
bteq << sushil2
.logon tdpid/user,password
.export report file=${mydatex};
select count(*) from dbc.tables;
.export reset
.exit
sushil2

Hope this helps.

Thanks!

Re: BTEQ script

I am working on a script and i want solution for the following problem :
If the SQL in BTEQ does not return any records , the email should not go out. If SQL returns any records then only email should go out.
I mean , if no records get return after executing the script, the email step should get skipped.
Enthusiast

Re: BTEQ script

Rajeev,

you can use activity count

select * From temp_table;

.IF ACTIVITYCOUNT = 0 THEN .QUIT 1
.IF ACTIVITYCOUNT > 0 THEN .QUIT 0

so if you don't get data then it will quit with CC=0001 and if query return data then get it will give you return code CC=0000 and based upon return code you can put check on e-mail step.