IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_warehouse_operation_1]') AND type = 'V')
DROP VIEW [dbo].[mps_warehouse_operation_1]
GO
create view [dbo].[mps_warehouse_operation_1] as 
SELECT [whop_id]
      ,[whop_cmpid]
      ,[whop_tag]
      ,[whop_prdid]
      ,case when whop_operation=-1 then [whop_whid] else whop_whid end whop_whid 
      ,[whop_opdate]
      ,[whop_operation]
      ,[whop_value]
      ,[whop_valuesuspend]
      ,[whop_bizid]
      ,[whop_type]
      ,[whop_no]
      ,[whop_ordid]
      ,[whop_branch]
      ,[whop_depart]
      ,[whop_creator]
      ,[whop_jbid]
 
      ,[whop_unit]
      ,[whop_batch]
      ,[whop_price]
      ,[whop_expire]
      ,[whop_note]
      ,whop_accountdate
      ,[whop_location]
  FROM [dbo].[mps_warehouse_operation]
  where whop_operation=-1 or whop_operation=0 
  union
  select 
  [whop_id]
      ,[whop_cmpid]
      ,[whop_tag]
      ,[whop_prdid]
      ,case when whop_operation=-1 then [whop_whid] else whop_whid end whop_whid 
      ,[whop_opdate]
      ,[whop_operation]
      ,[whop_value]
      ,[whop_valuesuspend]
      ,[whop_bizid]
      ,[whop_type]
      ,[whop_no]
      ,[whop_ordid]
      ,[whop_branch]
      ,[whop_depart]
      ,[whop_creator]
      ,[whop_jbid]

      ,[whop_unit]
      ,[whop_batch]
      ,[whop_price]
      ,[whop_expire]
      ,[whop_note]
      ,whop_accountdate
      ,[whop_location]
  FROM [dbo].[mps_warehouse_operation_history]
  where whop_operation=-1 or whop_operation=0