All Forums Tools
argun 2 posts Joined 09/10
09 Sep 2010
BTEQ script

how to append date to export filename in BTEQ script.

.export file =export_file_name_09092010

sushil.nayak 6 posts Joined 09/10
10 Sep 2010

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

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

Hope this helps.


rajeevh 1 post Joined 08/11
21 Aug 2011

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.

Langaliya.Nirav 15 posts Joined 04/11
24 Aug 2011


you can use activity count

select * From temp_table;


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.

--Nirav Langaliya

You must sign in to leave a comment.