sql-server – create function必须是批处理中唯一的语句

前端之家收集整理的这篇文章主要介绍了sql-server – create function必须是批处理中唯一的语句前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我从函数中得到这个错误
  1. CREATE FUNCTION getLavel(@id int,@lavel char)
  2. RETURNS date
  3. BEGIN
  4. DECLARE @date date
  5. select @date = (select authorization_date from Authorized WHERE diver_number = @id and @lavel =level_name)
  6. return @date
  7. END
  8. GO

可能是什么原因?

非常.

解决方法

将其转换为内联表值函数.这将比标量函数表现更好.此外,您不应使用字符数据类型的默认大小.你知道char的默认长度是多少吗?你知道它可以根据使用情况而有所不同吗?
  1. CREATE FUNCTION getLavel
  2. (
  3. @id int,@lavel char --You need to define the length instead of the default length
  4. )
  5. RETURNS table
  6. return
  7. select authorization_date
  8. from Authorized
  9. WHERE diver_number = @id
  10. and @lavel = level_name
  11.  
  12. GO

猜你在找的MsSQL相关文章