Multiple Line If Body translation planned to be delivered in the future.
Some parts in the output code are omitted for clarity reasons.
Severity
Medium
Description
Most of the cases inIF statements that contain a Begin ... End block inside their body are supported. This is a successful scenario (no SSC-EWI-TS0049 generated).
--** SSC-FDM-0029 - USER DEFINED FUNCTION WAS TRANSFORMED TO SNOWFLAKE PROCEDURE **CREATEORREPLACEPROCEDURE PURCHASING.FOO (STATUSINT)RETURNSVARCHARLANGUAGESQLCOMMENT ='{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"transact"}}'EXECUTEASCALLERAS$$DECLARE RESULT INT :=10;BEGINSELECT quantityINTO :RESULTFROM TABLE1WHERE COL1 = :STATUS;IF (:RESULT =3) THENBEGINIF (:RESULT >0) THENSELECT0INTO :RESULT;ELSESELECT1INTO :RESULT;ENDIF;SELECT1INTO :RESULT;END;ENDIF;RETURN :RESULT;END;$$;
In a general code example (Like the on top) the conversion is done successfully. But there are some edge cases where the "IF" statement is not converted and the EWI will be generated.
Manual Support
Case 1: Single Statement
For these cases, the transformation would be straightforward, since the transformed statement would appear in a select clause
IF @result =0BEGINSET @result =1END
CASEWHEN (SELECT RESULT FROM CTE2)=0THEN( SELECT1AS RESULT )
Case 2: Multiple Statements
For cases in which multiple statements are being transformed, we should transform the N Statement, and use it as the source table for the N+1 Statement.
IF @result =0BEGIN Statement1 Statement2 Statement3END
CASEWHEN (SELECT RESULT FROM CTE2)=0THEN(SELECT TransformedStatement3FROM (SELECT TransformedStatement2FROM (SELECT TransformedStatement1 ) T1 ) T2)
Case 3: Multiple set statements
For these cases, it will be necessary to replicate a transformation for each set statement.
IF @result =0BEGINSET @var1 =1SET @var2 =3SET @var3 = @var2END
WITH CTE1 AS (SELECTCASEWHEN (SELECT RESULTFROM CTE0) =0THEN (SELECT1) AS VAR1)WITH CTE2 AS (SELECTCASEWHEN (SELECT RESULTFROM CTE0)=0THEN (SELECT3) AS VAR2)WITH CTE3 AS (SELECTCASEWHEN (SELECT RESULTFROM CTE0)=0THEN (SELECT T1.VAR2 FROM ((SELECT3) AS VAR2) AS T1) AS VAR3) ...