I'm using table values for the first time as a parameter to a function in SQL Server 2008. The code below produces this error:
Must declare the scalar variable "@RESULT".
Why?! I'm declaring it on the first line of the function!
ALTER FUNCTION f_Get_Total_Amount_Due(
@CUSTOMER_LIST [tpCSFM_CUSTOMER_SET_FOR_MONEY] READONLY
)
RETURNS [tpCSFM_CUSTOMER_SET_FOR_MONEY]
AS
BEGIN
--Prepare the return value, start with initial customer list
DECLARE @RESULT AS [tpCSFM_CUSTOMER_SET_FOR_MONEY]
INSERT INTO @RESULT SELECT * FROM @CUSTOMER_LIST
--Todo: populate with real values
UPDATE @RESULT SET tpCSAM_MONEY_VALUE = 100
--return total amounts as currency
RETURN @RESULT
END