日期:2014-05-18  浏览次数:20664 次

求指教SQL函数
写个函数发现总是说第六行@num附近有错误,求指教!!!
这个函数只是来算一下某一读者借了多少本书
create function numBook(@readerName varchar(20))
returns int
as
begin
declare @num int;
select COUNT(*) into @num 
from t_borrow,t_reader2 
where t_borrow.readerId=t_reader2.readerId 
and t_reader2.readerName=@readerName
group by readerId;
return @num;
end


------解决方案--------------------
SQL code


create function numBook(@readerName varchar(20))
returns int
as
begin
declare @num int;
select @num=COUNT(*) 
from t_borrow,t_reader2  
where t_borrow.readerId=t_reader2.readerId  
and t_reader2.readerName=@readerName
group by readerId;
return @num;
end

--select count(*) into @num是Oracle中的语法

------解决方案--------------------
探讨

oh。。。我错了,用group by只是同学建议我试试。。。现在去掉了,然后也改过来了,不报错了。多谢啊!那个,再弱弱的问,要怎么调用啊。。。