CREATE TRIGGER Del_Mat_Consume_Doc_Detail ON dbo.Mat_Consume_Doc_Detail_n FOR DELETE AS Declare @Ldec_Quantity Numeric(12,2),@Ls_Mat_Id Varchar(20),@Ls_Item_Id Varchar(20),@Ldec_Money Numeric(12,2)
declare del_I_Mat_Consume_Doc cursor for
select Item_Id,Mat_Id,Quantity,Stock_Total_Prices from Deleted open del_I_Mat_Consume_Doc
fetch next from del_I_Mat_Consume_Doc into @Ls_Item_Id,@Ls_Mat_Id,@Ldec_Quantity,@Ldec_Money
while @@fetch_status=0 begin Update I_InitMaterial Set MExistStock = MExistStock + @Ldec_Quantity , MStockMoney = MStockMoney + @Ldec_Money Where MaterialID = @Ls_Mat_Id fetch next from del_I_Mat_Consume_Doc into @Ls_Item_Id,@Ls_Mat_Id,@Ldec_Quantity,@Ldec_Money end
FOR DELETE
AS
Declare @Ldec_Quantity Numeric(12,2),@Ls_Mat_Id Varchar(20),@Ls_Item_Id Varchar(20),@Ldec_Money Numeric(12,2)
declare del_I_Mat_Consume_Doc cursor for
select Item_Id,Mat_Id,Quantity,Stock_Total_Prices from Deleted open del_I_Mat_Consume_Doc
fetch next from del_I_Mat_Consume_Doc into @Ls_Item_Id,@Ls_Mat_Id,@Ldec_Quantity,@Ldec_Money
while @@fetch_status=0
begin
Update I_InitMaterial Set MExistStock = MExistStock + @Ldec_Quantity , MStockMoney = MStockMoney + @Ldec_Money Where MaterialID = @Ls_Mat_Id
fetch next from del_I_Mat_Consume_Doc into @Ls_Item_Id,@Ls_Mat_Id,@Ldec_Quantity,@Ldec_Money
end
CLOSE del_I_Mat_Consume_Doc
DEALLOCATE Del_I_Mat_Consume_Doc