BTEQ: If Else condition

Database
Enthusiast

BTEQ: If Else condition

 
Tags (3)
4 REPLIES
Enthusiast

Re: BTEQ: If Else condition

Hi Guys,

I have the below requirement, can this be implemented in a single BTEQ:

SELECT ....;

.IF ACTIVITY_COUNT=0

THEN

DO an Insert;

EXIT with a return code A;

ELSE

Do a set of Insert, Updates;

EXIT with a return code B;

I am aware that a THEN in a .IF..THEN has to be followed by .EXIT But is there any way by which i can achieve this (may be using .GOTO LABEL)

Note: I have done it by writing a function (Unix, BTEQ mix) and using it in the parent script but i am looking for some alternative ways.

Thanks in advance

Re: BTEQ: If Else condition

 .logmech ldap
    .logon ${SERVER}/${USER},${PASSWORD}
    .SET TITLEDASHES OFF
 
select 1 from dbc.TablesV where databasename = database and TabkeName = 'table_$CURR_DT';
 
.IF ACTIVITYCOUNT = 0 THEN GOTO OK
 
DROP TABLE TABLE_$CURR_DT;
--avoid using numbers less than 10.
.exit 15
 
.LABEL OK
 
CREATE TABLE TABLE_$CURR_DT AS (SEL * FROM TABLEXXX) WITH DATA;

    .exit 20
Enthusiast

Re: BTEQ: If Else condition

bteq<<BTEQ>$FILELOG
.logon $vServer/$vUser, $vPassword
.SET DEFAULTS
.SET TITLEDASHES OFF
.SET WIDTH 254
SEL DATE,TIME;

SELECT tablename
FROM dbc.tables
WHERE databasename = 'MY_DATABASE'
AND tablename = 'MY_TABLE';

.IF ACTIVITYCOUNT = 0 THEN .GOTO CREATE
drop table MY_DATABASE.MY_TABLE;

.LABEL CREATE
CREATE MULTISET TABLE MY_DATABASE.MY_TABLE
AS (
SELECT
A.Field1
,A.Field2
FROM MY_TABLE_A A
) WITH DATA
PRIMARY INDEX (Field1)
;

.IF ERRORCODE <> 0 THEN .GOTO ERRORFOUND

COLLECT STAT INDEX (Field1) ON MY_DATABASE.MY_TABLE;

.LABEL SALIR
.exit 0

.LABEL ERRORFOUND
.REMARK '#### ERROR inesperado'
.EXIT ERRORCODE

.LOGOFF;
.QUIT 0;
Enthusiast

Re: BTEQ: If Else condition

Thnks Guys

Tags (1)