611
社区成员
发帖
与我相关
我的任务
分享
CREATE trigger bom_mb_update
on bom_mb for update
as
Declare @temp_item_id VarChar(40),
@new_item_id VarChar(40),
@old_item_id VarChar(40),
@item_name VarChar(40),
@quantity decimal(18,6),
@itemfac VarChar(40),
@pare_item_id VarChar(40)
Select @temp_item_id = temp_item_id, @new_item_id=item_id,
@item_name = item_name, @quantity= quantity ,@itemfac= itemfac
from inserted
Select @old_item_id = item_id
from deleted
if @itemfac ='B'or @itemfac='A'
begin
update bom set item_id= @new_item_id, item_name=@item_name, quantity= @quantity
where pare_item_id = @temp_item_id
and item_id = @old_item_id
--print '@@rowcount'+cast(@@rowcount as char(5))
end
if @itemfac ='R'
begin
--
Declare pare_id_cursor CURSOR for
select item_id from bom
where pare_item_id = @temp_item_id --创建游标
For UPDATE OF item_id,item_name,quantity --定义可更新列
Open pare_id_cursor
--执行第一次取数操作、将游标定位到第一行记录
Fetch next from pare_id_cursor into @pare_item_id
WHILE @@FETCH_STATUS = 0
begin
begin
update bom set item_id= @new_item_id, item_name=@item_name, quantity= @quantity
where item_id = @old_item_id
and pare_item_id = @pare_item_id
--定位到下一行记录
end
Fetch next from pare_id_cursor into @pare_item_id
end
close pare_id_cursor --关闭游标
deallocate pare_id_cursor --释放游标资源
end commit
dw_1.AcceptText()
if dw_2.ModifiedCount()=0 and dw_2.DeletedCount()=0 then
MessageBox("提示信息","尚无增加、删除或修改,无需保存!")
return
end if
//dw_2.ResetUpdate()
if dw_2.update()=1 then
Commit;
MessageBox("提示信息","dw_2 保存成功!")
else
RollBack;
MessageBox("提示信息","保存失败!")
end if