10 May 2013

Using BTEQ Conditional Logic


Using BTEQ Conditional Logic

Below is a BTEQ batch script example. The initial steps of the script will establish the logon, the database, and the delete all the rows from the Employee_Table. If the table does not exist, the BTEQ conditional logic will instruct Teradata to create it. However, if the table already exists, then Teradata will move forward and insert data.
Note: In script examples, the left panel contains BTEQ base commands and the right panel provides a brief description of each command.

.RUN FILE = mylogon.txt
Logon to Teradata
DATABASE SQL_Class;
Make the default database SQL_Class
DELETE FROM Employee_Table;
Deletes all the records from the Employee_Table.
.IF ERRORCODE = 0 THEN .GOTO INSEMPS
/* ERRORCODE is a reserved word that contains the outcome status for every SQL statement executed in BTEQ. A zero (0) indicates that statement worked. */
BTEQ conditional logic that will check to ensure that the delete worked or if the table even existed.
image\img00357.gif
If the table did not exist, then BTEQ will create it. If the table does exist, the Create table step will be skipped and directly GOTO INSEMPS.
.LABEL INSEMPS

INSERT INTO Employee_Table (1232578, ‘Chambers’
,’Mandee’, 48850.00, 100);
INSERT INTO Employee_Table (1256349, ‘Harrison’
,’Herbert’, 54500.00, 400);

.QUIT

No comments:

Post a Comment