蚂蚁或大力,快!急!
我建立一个触发齐,利用游标来更新数据库表中的数据;因为定义游标记录集的时候要利用到参数来控制选择的范围,所以造成不能错误!Read-Only游标上不能定义Update!
程序代码:
Create Trigger AddContainerTrigger
On DepotPosition
For INSERT
As
Declare @Row int,@Layer int,@Area varchar(20),@Col int,@Serial int
Select @Area=AreaCode,@Layer=LayerCode,@Row=RowCode,@Col=ColCode
From Inserted
Declare AddContainer Cursor
For
select OutSerial from DepotPosition where RowCode<@Row and AreaCode=@Area and ColCode=@Col
For update
open AddContainer
Fetch next from AddContainer into @Serial
while(@@fetch_Status=0)
begin
update DepotPosition set OutSerial=@Serial+1
where current of AddContainer
Fetch next from AddContainer into @Serial
end
Close AddContainer
Deallocate AddContainer
select OutSerial from DepotPosition