我是 SQL 新手,试图在 MS SQL 2008R2 中创建函数,但不能在函数内声明变量。这段代码有什么问题?
CREATE FUNCTION denominator() RETURNS int
BEGIN
DECLARE @Count;
-- Some logic here
END;
GO
SELECT dbo.denominator()
DROP FUNCTION denominator
我遇到了这种错误:
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.