I'm newbie in SQL and trying to create function in MS SQL 2008R2, but can't declare variable inside function. What's wrong with this code?
CREATE FUNCTION denominator() RETURNS int
BEGIN
DECLARE @Count;
-- Some logic here
END;
GO
SELECT dbo.denominator()
DROP FUNCTION denominator
I'm getting that kind of errors:
Msg 102, Level 15, State 1, Procedure denominator, Line 3
Incorrect syntax near ';'.
Msg 4121, Level 16, State 1, Line 1
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.denominator", or the name is ambiguous.