Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create function must be the only statement in the batch

Tags:

sql-server

I'm getting this error from the function:

CREATE FUNCTION getLavel(@id int ,@lavel char)
RETURNS date
BEGIN
 DECLARE @date date
    select @date = (select authorization_date from Authorized WHERE diver_number = @id and @lavel =level_name)
    return @date
END
GO

What can be the reason?

Ty very much.

like image 331
user3885474 Avatar asked Jul 28 '14 19:07

user3885474


People also ask

How do you drop a function in SQL?

The syntax to a drop a function in SQL Server (Transact-SQL) is: DROP FUNCTION function_name; function_name. The name of the function that you wish to drop.


1 Answers

The function needs to be either the only function in the query window OR the only statement in the batch. If there are more statements in the query window, you can make it the only one "in the batch" by surrounding it with GO's.

e.g.

GO
CREATE FUNCTION getLavel(@id int ,@lavel char)
RETURNS date
BEGIN
 DECLARE @date date
    select @date = (select authorization_date from Authorized WHERE     diver_number = @id and @lavel =level_name)
    return @date
END
GO
like image 178
nicV Avatar answered Sep 23 '22 06:09

nicV