Example: Using FOR Loop Aliases in Searched CASE - Teradata Vantage - Analytics Database

SQL Stored Procedures and Embedded SQL

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2023-10-30
dita:mapPath
frc1628111662093.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
rjx1472253414573
lifecycle
latest
Product Category
Teradata Vantage™

The following example illustrates the use of FOR loop aliases in the conditional expressions of a searched CASE statement:

CREATE PROCEDURE spSample()
Label1:BEGIN
    FOR RowPointer AS
        c_employee CURSOR FOR
        SELECT DeptNo AS c_DeptNo,
            employeeid AS c_empid FROM Employee
    DO
        CASE
     WHEN RowPointer.c_DeptNo > 10 THEN
        INSERT INTO Dept VALUES (RowPointer.c_DeptNo,
                                RowPointer.c_empid) ;
     WHEN RowPointer.c_DeptNo <= 10 THEN
        UPDATE Employee
           SET DeptNo = RowPointer.c_DeptNo + 10 ;
        INSERT INTO Dept VALUES (RowPointer.c_DeptNo,
                                RowPointer.c_empid)
   END CASE;
    END FOR;
END Label1;