Hello i am trying to create a function in ms sql server that accepts an integer parameter and returns a varchar. I am however having some trouble implementing this and would really love some help with this:
CREATE FUNCTION GetCategory (@CategoryID int)
RETURNS int
AS
BEGIN
DECLARE @Category varchar(64)
@Category = (SELECT Category
FROM Categories
WHERE CategoryID = @CategoryID)
RETURN @Category
END
The code above is what i tried doing already. I get the following error upon execution:=:
Msg 102, Level 15, State 1, Procedure GetCategory, Line 7
Incorrect syntax near '@Category'.
Msg 137, Level 15, State 2, Procedure GetCategory, Line 11
Must declare the scalar variable "@Category".