MSCEWI4053

Multiple selects in if body were partially transformed.

Severity

High

Description

This EWI is added to one or more resulting CTEs of a UDF transformation that generates a Snowflake function, when the IF statement that was the source for such CTE only contained variable assignments using the SELECT @local_variable syntax.

Even though this EWI's severity is set to high, the basic scenarios like the one from the code example are proven to work as intended, however depending on the complexity of each individual SELECT statement, and the overall amount of statements inside the IF's BEGIN ... END block, the functional equivalence of the result compared to the input code cannot be guaranteed.

Code Example

Input Code:

CREATE or ALTER FUNCTION PURCHASING.SELECTINUDF (
    @param1 varchar(12)
)
RETURNS int
AS
BEGIN
    declare @var1 int;
    declare @var2 int;
    declare @var3 int;

    IF @param1 = 'first'
    BEGIN
        select @var1 = col1 + 10 from table1 WHERE id = 0;
        select @var2 = col1 + 20 from table1 WHERE id = 0;
        select @var3 = col1 + 30 from table1 WHERE id = 0;
    END

    RETURN @var1
END

Output Code:

Recommendations

Last updated