All Forums Database
SwapSays 2 posts Joined 02/16
05 Feb 2016
BTEQ: If Else condition
SwapSays 2 posts Joined 02/16
05 Feb 2016

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

pathanjali 4 posts Joined 12/14
01 Jun 2016

 .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

 

--Pathanjali
"Great minds discuss ideas; average minds discuss events; small minds discuss people"

Kbos 20 posts Joined 04/13
02 Jun 2016
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;

 

You must sign in to leave a comment.