Create Function Must Be The Only Statement In The Batch


Answer :

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


Turn this into an inline table valued function. This will perform better than the scalar function. Also, you should NOT use the default sizes for character datatypes. Do you know what the default length for a char is? Did you know that it can vary based on usage?



CREATE FUNCTION getLavel
(
@id int
, @lavel char --You need to define the length instead of the default length
)
RETURNS table
return
select authorization_date
from Authorized
WHERE diver_number = @id
and @lavel = level_name

GO


You need to add RETURN before the END statement



That should fix your issue, that's what fixed mine. :D



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable