create function必须是批处理的仅有语句

不知道怎么改了
麻烦帮我看看


create function f_Profit(@lb char(10)) 
RETURNS @ProfitTable  table(
goodid char(10),
sumprofit int)
as
begin
insert into @ProfitTable
select a.goodid,SUM(salenum*(saleprice-goodprice)) as sumprofit
from a join b on a.goodid=b.goodid
where a.goodid in(select goodid from a where goodlb=@lb)
group by a.goodid
order by sumprofit desc
end
return
GO

稍微改动了下,想在什么平台上运行

CREATE FUNCTION f_Profit(@lb char(10))
RETURNS @ProfitTable  table(
goodid char(10),
sumprofit int)
as
begin
insert into @ProfitTable
select a.goodid,SUM(salenum*(saleprice-goodprice)) as sumprofit
from a join b on a.goodid=b.goodid
where a.goodid in(select goodid from a where goodlb=@lb)
group by a.goodid
order by sumprofit desc
end
go





  • 这篇博客: 数据库系统原理 - - (5)数据库编程中的 1)使用CREATE FUNCTION语句创建存储函数 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • CREATE FUNCTION sp_name([func_parameter[,...]])
    RETURNS type
    routine_body
    

    在这里插入图片描述