17.10 - Example: Creating a Procedure with Multistatement Request Using a Dynamic SQL Call Statement - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1144-171K
Language
English (United States)

Following is an example of a dynamic SQL call using DBC.SysExecSQL.

    CREATE PROCEDURE salesadjust(IN item    INTEGER, 
                                 IN numsold INTEGER)
      BEGIN
        DECLARE  price DECIMAL(8,2);
        DECLARE  update1, update2 VARCHAR(128);
        SELECT item_price INTO price 
        FROM PriceTbl 
        WHERE item = pricetbl.item_no;
        SET Update1 = 'UPDATE sales_summary' ||
         'SET total_sales = total_sales + ' ||
         price ' || ' * ' || numsold || 
         'WHERE ' || item || ' = sales_summary.item_no;';
        SET update2 = 'UPDATE inventory' ||
         'SET item_no = item_no -' || numsold
         'WHERE ' || item || ' = inventory.item_no;';
       BEGIN REQUEST
        CALL dbc.SysExecSQL(update1 || update2);
       END REQUEST;
      END;