MSCEWI4040

Value overwritten, check function equivalence.

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:

CREATE OR ALTER FUNCTION PURCHASING.FOO2() 
RETURNS MONEY
AS
BEGIN
	declare @firstValue MONEY
	declare @secondValue MONEY
	declare @Result MONEY
	select  @Result = 0
	select 	@firstValue = SubTotal from Purchasing.PurchaseOrderHeader where PurchaseOrderID = 1
	select 	@secondValue = SubTotal from Purchasing.PurchaseOrderHeader where PurchaseOrderID = 2
	if @firstValue is not null
		select @Result = @firstValue
	if @secondValue is not null
		select @Result = @secondValue
	return @Result 
END

Output Code:

Recommendations:

Last updated