MSCEWI2087

GOTO statement was removed due to if statement inversion

This is a deprecated version of the SnowConvert documentation, please visit the official site HERE.

Severity

Medium

Description

It is common to use GOTO command with IF and LABEL commands to replicate the functionality of an SQL if statement. When used in this way, it is posible to transform them directly into an if, if-else or even an if-elseif-else statement. However, in these cases, the GOTO commands become unnecessary and should be removed to prevent them from being replaced by a LABEL section.

Example code

Input code

.If ActivityCount = 0 THEN .GOTO endIf
DROP TABLE TABLE1;
.Label endIf
SELECT A FROM TABLE1;

Output code

EXECUTE IMMEDIATE
$$
DECLARE
STATUS_OBJECT OBJECT;
BEGIN
IF (NOT (STATUS_OBJECT['SQLROWCOUNT'] = 0)) THEN
      /*** MSC-ERROR - MSCEWI2087 - GOTO endIf WAS REMOVED DUE TO IF 
      STATEMENT INVERSION ***/
 
      BEGIN
            DROP TABLE TABLE1;
            STATUS_OBJECT := OBJECT_CONSTRUCT('SQLROWCOUNT', SQLROWCOUNT);
      EXCEPTION
             WHEN OTHER THEN
             STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
      END;
       /*** MSC-WARNING - MSCEWI1002 - REMOVED NEXT STATEMENT, NOT APPLICABLE IN SNOWFLAKE.  ***/
        /*.Label Continue_No_Rejects_00*/
 
END IF;
BEGIN
       SELECT
       A FROM
       TABLE1;
       STATUS_OBJECT := OBJECT_CONSTRUCT('SQLROWCOUNT', SQLROWCOUNT);
EXCEPTION
       WHEN OTHER THEN
        STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
END;
END
$$";

Recommendations

Last updated