求各位大神检查下一下代码对不对
求各位大神检查下一下代码对不对,
实现功能是,检查创建一个存储过程。在存储过程中分别根据每位销售员自身的销售下限,对所有销售员的订单进行审批(销售员入职后登记基本人员信息。每个销售人员都有各自的销售额下限,也就是说销售员下的每张订单的合计销售额都必须超过自身的销售额下限,才能审批通过,否则订单被驳回。)。若存储过程在执行时抛异常就返回数字0,否则,执行完毕就返回数字1。
代码如下:
declare @Seller char(20) //订单表的销售员
declare @Esale int  //订单表的销售额
declare @Llimit int//销售员表的销售下限
declare @counter int //计数器
set @counter = 0
create cursor c1
as
select Esale,Seller
from Order //订单表
create proc check
as
begin
open c1
fetch c1 into @Seller,@Esale,@Llimit
while c1%found
loop
select Llimit
into @Llimit
from Emp
where Seller = @Seller
if @Esale < @Llimit
then @counter = 0;
else
then @counter =1;
end if;
fetch c1 into@Seller,@Esale,@Llimit
end loop;
end;
              
              
------解决方案--------------------create PROCEDURE check
as
begin
	declare @Seller char(20) //订单表的销售员
	declare @Esale int  //订单表的销售额
	declare @Llimit int//销售员表的销售下限
	declare @counter int //计数器
	
	set @counter = 0
	declare  cursor c1
	for  select Seller,Esale,Llimit  from Order //订单表
	
	open c1
	fetch next from @Seller,@Esale,@Llimit
	while @@FETCH_STATUS = 0
	begin 
		select Llimit  into @Llimit  from Emp  where Seller = @Seller
		if (@Esale > @Llimit)
		      set @counter =@counter+1
		fetch next from  @Seller,@Esale,@Llimit
	end 
	print '审核通过'+@count+'人'
end