BTEQ script help

Database
Enthusiast

BTEQ script help

I am not familiar with bteq and scripting capabilities. I need to write a teradata script that is invoked by a unix shell under cron and checks to see if the data has been updated in a specific table. If the data is updated, either echo a response to the system or write out a response to a flat file like "Yes". If the data is not updated, loop and check again up to 5 times.
Any syntax sql is greatly appreciated.
1 REPLY
Junior Contributor

Re: BTEQ script help

There are no built in loops in BTEQ, so you have two possibilities:

- Do the loop in the unix shell, but then you have to logon several times.
- repeat the same stuff 5 times in BTEQ.

.logon ...

select 1 where exists
(your select query to check for updates);

.if activity_count > 0 then .goto ok;

.hang 10 -- this waits for 10 seconds, because you probably don't want to rerun the test immediately.

--cut $ paste sel/if/hang 3 times
select 1 where exists
(your select query to check for updates);

.if activity_count > 0 then .goto ok;
.goto notfound;

.label ok;
.export file = flatfile.txt;
select 'YES' (title '');
.export reset;

.label notfound;
.quit;

Dieter