Some parts in the output code are omitted for clarity reasons.
Basic Teradata Query (BTEQ) is a general-purpose, command-based program that enables users on a workstation to communicate with one or more Teradata Database systems and to format reports for both print and screen output.
The BTEQ content is relocated within an EXECUTE IMMEDIATE block to transfer the BTEQ script functionality to Snowflake SQL executable code.
All the DML and DDL statements inside BTEQ scripts are supported by SnowConvert AI and successfully translated to Snowflake SQL. The commands that do not have support yet, or do not have support at all, are being marked with a warning message and commented out.
SnowConvert AI supports the migration of BTEQ code with Bash Variable Placeholders used for shell scripts. These placeholders are migrated to Snowflake CLI template syntax (<%VAR%>) and SSC-FDM-TD0003 is added to the code. Please consider the following when migrating code with these placeholders:
SnowConvert AI does not support the migration of shell scripts. To migrate the BTEQ code, isolate it in a BTEQ file and supply it as input for the tool.
Snowflake CLI is required to execute the migrated code. Variables are passed via -D flags: snow sql -f script.sql -D "VAR=value". For more information, see SSC-FDM-TD0003.
When the BTEQ script target is Snowflake Scripting (SnowScript), SnowConvert AI translates .IF, .GOTO, and .LABEL by modeling jumps as nested procedure calls and early returns inside a single EXECUTE IMMEDIATE … `` block. Snowflake does not provide BTEQ-style goto/label semantics.
BTEQ construct
Snowflake Scripting approach
Script body with labels
Wrapped in EXECUTE IMMEDIATE … `` with DECLARE, nested procedures, and a top-level BEGIN … END
.LABEL name
Section name becomes a nested procedure; handoffs use CALL name();
.GOTO name
CALL name(); followed by RETURN 'PROCESS FINISHED';
.IF ERRORCODE …
IF (STATUS_OBJECT['SQLCODE'] …) using a status object updated in EXCEPTION handlers
.IF ACTIVITYCOUNT …
IF on row count from TABLE(RESULT_SCAN(LAST_QUERY_ID()))
Error/status tracking
STATUS_OBJECT holds status fields; generated SQL may include SSC-FDM-TD0013 (Snowflake SQLCODE is not the same as Teradata ERRORCODE)
Note
To produce output in this form, set the Teradata/BTEQ script output to Snowflake Scripting (for example -- Additional Params: -q SnowScript in the samples below). Option names vary by interface; see the SnowConvert AI user guide for your product version.
The following example shows .IF ERRORCODE with .GOTO and .LABEL. Teradata BTEQ often branches on ERRORCODE after DDL and jumps to a labeled cleanup or next step.
EXECUTEIMMEDIATE$$
DECLARE
SC_EXIT_CODE VARCHAR := 0;
STATUS_OBJECT OBJECT := OBJECT_CONSTRUCT('SQLCODE', 0) /*** SSC-FDM-TD0013 - THE SNOWFLAKE ERROR CODE MISMATCH THE ORIGINAL TERADATA ERROR CODE ***/;
SC_PROCESS PROCEDURE ()
RETURNS VARCHAR
AS
BEGIN
DROP TABLE DP_DWEDW.TF035_PCOM_PROD_TRAT_SEL;
IF (STATUS_OBJECT['SQLCODE'] /*** SSC-FDM-TD0013 - THE SNOWFLAKE ERROR CODE MISMATCH THE ORIGINAL TERADATA ERROR CODE ***/ != 0) THEN
CALL CRIA_EXPRESS_1();
RETURN 'PROCESS FINISHED';
END IF;
CALL CRIA_EXPRESS_1();
EXCEPTION
WHEN OTHER CONTINUE THEN
STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
END;
CRIA_EXPRESS_1 PROCEDURE ()
RETURNS VARCHAR
AS
BEGIN
DROP TABLE DP_DWEDW.TF035_DESCTO_EXPRESS;
IF (STATUS_OBJECT['SQLCODE'] /*** SSC-FDM-TD0013 - THE SNOWFLAKE ERROR CODE MISMATCH THE ORIGINAL TERADATA ERROR CODE ***/ != 0) THEN
CALL CRIA_EXPRESS_2();
RETURN 'PROCESS FINISHED';
END IF;
CALL CRIA_EXPRESS_2();
EXCEPTION
WHEN OTHER CONTINUE THEN
STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
END;
CRIA_EXPRESS_2 PROCEDURE ()
RETURNS VARCHAR
AS
BEGIN
DROP TABLE DP_DWEDW.TF035_DEVOL_EXPRESS;
EXCEPTION
WHEN OTHER CONTINUE THEN
STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
END;
BEGIN
CALL SC_PROCESS();
RETURN SC_EXIT_CODE;
END
$$;
After each statement that can set SQL state, the generated IF checks STATUS_OBJECT['SQLCODE']. On error, the script calls the target label procedure and returns from the current procedure so later statements in that section do not run. On success, it calls the next section’s procedure to continue the original linear flow.
The next example shows .IF ActivityCount = 0 THEN .GOTO …, expressed in Snowflake Scripting using the last query id and RESULT_SCAN.
EXECUTEIMMEDIATE$$
DECLARE
SC_EXIT_CODE VARCHAR := 0;
STATUS_OBJECT OBJECT := OBJECT_CONSTRUCT('SQLCODE', 0) /*** SSC-FDM-TD0013 - THE SNOWFLAKE ERROR CODE MISMATCH THE ORIGINAL TERADATA ERROR CODE ***/;
SC_PROCESS PROCEDURE ()
RETURNS VARCHAR
AS
BEGIN
IF ((SELECT
COUNT(*)
FROM
TABLE(RESULT_SCAN(LAST_QUERY_ID()))) = 0) THEN
CALL Continue_No_Rejects_00();
RETURN 'PROCESS FINISHED';
END IF;
DROP TABLE DROPTEDTABLE1;
CALL Continue_No_Rejects_00();
EXCEPTION
WHEN OTHER CONTINUE THEN
STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
END;
Continue_No_Rejects_00 PROCEDURE ()
RETURNS VARCHAR
AS
BEGIN
SELECT
A
FROM
AUDITORIA;
EXCEPTION
WHEN OTHER CONTINUE THEN
STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
END;
BEGIN
CALL SC_PROCESS();
RETURN SC_EXIT_CODE;
END
$$;
If activity count is zero, the generated script jumps to the label section with CALL Continue_No_Rejects_00() and RETURN 'PROCESS FINISHED', skipping DROP TABLE DROPTEDTABLE1. Otherwise it runs DROP TABLE, then calls the label procedure to run SELECT A FROM AUDITORIA.
There may be BTEQ commands that do not have an equivalent in Snowflake SQL
Since BTEQ is a command-based program, there may be some commands in your input code that do not have a hundred percent functional equivalence in Snowflake SQL. Those particular cases are identified, marked with warnings in the output code, and documented in the further pages.