WHILE

Translation reference to convert Teradata WHILE statement to Snowflake Scripting

Some parts in the output code are omitted for clarity reasons.

Description

Teradata's WHILE statement is translated to Snowflake ScriptingWHILE syntax.

For more information on Teradata While, check here.

[label_name:] WHILE conditional_expression DO
    { sql_statement }
END WHILE [label_name];

Sample Source Patterns

Teradata

IN -> Teradata_01.sql
REPLACE PROCEDURE whileProcedure(OUT resultCounter INTEGER)
BEGIN
    DECLARE counter INTEGER DEFAULT 0;
    customeLabel: WHILE counter < 10 DO
        SET counter = counter + 1;
    END WHILE customeLabel;
    SET resultCounter = counter;
END;

CALL whileProcedure(:?);

Snowflake Scripting

OUT -> Teradata_01.sql
CREATE OR REPLACE PROCEDURE whileProcedure (
--                                            OUT
                                                RESULTCOUNTER INTEGER)
RETURNS VARIANT
LANGUAGE SQL
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "teradata",  "convertedOn": "07/24/2024" }}'
EXECUTE AS CALLER
AS
$$
    DECLARE
        counter INTEGER DEFAULT 0;
    BEGIN
         
        WHILE ( counter < 10) LOOP
            counter := counter + 1;
        END LOOP CUSTOMELABEL;
        resultCounter := counter;
        RETURN resultCounter;
    END;
$$;

CALL whileProcedure(:?);

Known Issues

No issues were found.

No related EWIs.

Last updated