All Forums Analytics
vazeer 1 post Joined 07/08
23 Jul 2008
if and else condition in bteq

hi , can any one help me,, how to use if and else condition in bteq,,,

Adeel Chaudhry 773 posts Joined 04/08
23 Jul 2008

Hello,You need to put a dot "." before IF as follows:.IF ACTIVITYCOUNT = 0 THEN .QUIT 65;HTH.Regards,Adeel

-- If you are stuck at something .... consider it an opportunity to think anew.

SN 77 posts Joined 01/07
24 Jul 2008

just to add to it...while using IF...THEN - when the condition evaluates to false, the it ignores the action in THEN clause and proceeds with the next command. so, nor explicit ELSE stmt with BTEQ IF...THEN but its obvious.thx

yamyro 3 posts Joined 04/15
22 Apr 2015

If you want to prove a method related with IF- ELSE but with Querys maybe this example can help you:

.LOGON IPSERVER/USR,PASSWORD; 

 

SELECT TOP 10 * FROM DB.TABLE; --Q1

 

.IF ERRORCODE !=0 THEN .GOTO DoQuery1; 

.IF ERRORCODE =0 THEN  .GOTO DoQuery2;

 

 

.LABEL DoQuery1; 

     SELECT TOP 1 * FROM DB.TABLE;  --Q2

    .GOTO End;

 

 

.LABEL DoQuery2; 

     SELECT TOP 2 * FROM DB.TABLE; --Q3 

    .GOTO End;

 

 

.LABEL End;

 

.LOGOFF; 

.EXIT; 

 

Depending of the result of Q1, the sequence of the bteq will be defined, if it goes to DoQuery1 or DoQuery2, but it's very important put de command .GOTO End to keep de estructure of the method IF-ELSE, if you don´t put it you can enter in a sequence where your code will process both Query´s (first Q2 and then Q3).

You must sign in to leave a comment.