I create a function that returns the result of a table
ALTER FUNCTION [brm].[fnComputeScores_NEW]
(
@var1 TINYINT
)
RETURNS
@ret TABLE
(
[producerid] INT
,[CityId] INT
, CityName VARCHAR(100)
)
AS
BEGIN
INSERT INTO @ret
SELECT [producerid], [CityId] from producers
RETURN
END
all right up to this point
but the code that I want to put in placeholder
UPDATE @ret
SET
CityName = Cities.Name
FROM
@ret JOIN Cities
ON @ret.CityId= Cities.CityId
generates a compilation error
Must declare the scalar variable "@ret".
Why? How to fix it?
source
share