IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_warehouse_operation_delete]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_warehouse_operation_delete]
GO
CREATE trigger [dbo].[mps_warehouse_operation_delete] on [dbo].[mps_warehouse_operation] for delete as
begin
    declare
       @numrows  int,
       @errno    int,
       @errmsg   varchar(255)

    select  @numrows = @@rowcount
    if @numrows = 0
       return

    
insert into mps_warehouse_operation_history(
whop_id,whop_cmpid,whop_prdid,whop_tag,whop_whid,whop_whid2,whop_opdate,whop_operation,whop_value,whop_valuesuspend,whop_bizid,whop_accountdate,
whop_type,whop_branch,whop_depart,whop_creator,whop_no,whop_ordid,whop_jbid,whop_unit,whop_batch,whop_price,whop_expire,whop_note,whop_location) 
select whop_id,whop_cmpid,whop_prdid,whop_tag,whop_whid,whop_whid2,whop_opdate,whop_operation,whop_value,whop_valuesuspend,whop_bizid,whop_accountdate,
whop_type,whop_branch,whop_depart,whop_creator,whop_no,whop_ordid,whop_jbid,whop_unit,whop_batch,whop_price,whop_expire,whop_note,whop_location 
from deleted where whop_back=1 

    return

/*  Errors handling  */
error:
    -- raiserror @errno @errmsg
    rollback  transaction
end