This is a deprecated version of the SnowConvert documentation, please visit the official site HERE.
Severity
Medium
Description
A variable value has been overwritten by a new value. The previous value may be inaccesible and may not be functionally equivalent.
Code Example
Input Code:
CREATEORALTERFUNCTION PURCHASING.FOO2() RETURNSMONEYASBEGINdeclare @firstValue MONEYdeclare @secondValue MONEYdeclare @Result MONEYselect @Result =0select @firstValue = SubTotal from Purchasing.PurchaseOrderHeader where PurchaseOrderID =1select @secondValue = SubTotal from Purchasing.PurchaseOrderHeader where PurchaseOrderID =2if @firstValue is not nullselect @Result = @firstValueif @secondValue is not nullselect @Result = @secondValuereturn @Result END
Output Code:
/*** MSC-WARNING - MSCEWI1069 - USER DEFINED FUNCTION INNER LOGIC WAS TRANSFORMED TO A SINGLE COMMON TABLE EXPRESSION ***/
CREATE OR REPLACEFUNCTIONPURCHASING.FOO2 ()RETURNSDOUBLE PRECISIONLANGUAGESQLAS$$WITH CTE1 AS (select0AS RESULT), CTE2 AS (select SubTotal AS FIRSTVALUE from Purchasing.PurchaseOrderHeader where PurchaseOrderID =1), CTE3 AS (select SubTotal AS SECONDVALUE from Purchasing.PurchaseOrderHeader where PurchaseOrderID =2), CTE5 AS (SELECTCASEWHEN (SELECT FIRSTVALUE FROM CTE2) is not nullTHEN (select--** MSC-ERROR - MSCEWI4040 - VARIABLE HAS OVERWRITTEN A PREVIOUS VALUE, CHECK EQUIVALENCE ** (SELECT FIRSTVALUE FROM CTE2) AS RESULT) END), CTE7 AS (SELECTCASEWHEN (SELECT SECONDVALUE FROM CTE3) is not nullTHEN (select--** MSC-ERROR - MSCEWI4040 - VARIABLE HAS OVERWRITTEN A PREVIOUS VALUE, CHECK EQUIVALENCE ** (SELECT SECONDVALUE FROM CTE3) AS RESULT) END) SELECT RESULT FROM CTE7$$;