在游标中如何跳出循环
--内容如下
CREATE PROCEDURE [Update_Delivery]
@custno varchar(6), -- 客户编号
@partno varchar(20), --产品编号
@qty numeric(18,8) -- 送货数量
AS
declare @req_qty1 numeric(18,8),@deliv_qty1 numeric(18,8),@id bigint
--定义一游标,查询相关的记录
declare cursor1 cursor for
select idno,require_quantity,Delivery_Quantity
from product_deliver_plan_list where part_no=@partno and customer_no=@custno
open cursor1
fetch next from cursor1 into @id,@req_qty1,@deliv_qty1
while @@fetch_status = 0
begin
if @qty>=@req_qty1-@deliv_qty1
update product_deliver_plan_list set delivery_quantity=@req_qty1-
@deliv_qty1,delivery_date=@de_date1,finish=1
where part_no=@part_no1 and customer_no=@cust_no1 and idno=@id
else
begin
update product_deliver_plan_list set
delivery_quantity=@de_qty1,delivery_date=@de_date1
where part_no=@part_no1 and customer_no=@cust_no1 and idno=@id
break --跳出循环不再执行下去
end
set @de_qty1=@de_qty1-@req_qty1+@deliv_qty1
fetch next from cursor1 into @id,@req_qty1,@req_date1,@deliv_qty1
end
close cursor1
deallocate cursor1
go
上述中我用break 跳出游标循环,不再往下执行,不知对否?
问题点数:20、回复次数:2Top
1 楼zarge(鲨去来兮)回复于 2005-03-01 16:57:00 得分 20
对Top
2 楼dongliu(一沙一世界,一花一天堂)回复于 2005-03-29 10:58:49 得分 0
你实际上是跳出while循环,用break当然可以
Top




