I’m trying to create a UDF in SQL Server 2005 Express as below:
CREATE FUNCTION [CombineValues] () RETURNS VARCHAR(8000) AS BEGIN DECLARE @CuisineList VARCHAR(8000); RETURN ( SELECT @CuisineList = COALESCE(@CuisineList + ', ', '') + CAST(Cuisine AS varchar(20)) FROM Cuisines ) END
Cuisines has the structure:
CuisineID INT PK, Cuisine VARCHAR(20)
When I try to create the function as above, I get an error:
Msg 102, Level 15, State 1, Procedure CombineValues, Line 10 Incorrect syntax near ‘=’.
What am I doing wrong?
This answer is from the original poster, Wild Thing. Please do not vote it up or down.