IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[order_191_modify_2]') AND type = 'P')
DROP PROCEDURE [dbo].[order_191_modify_2]
GO

-- 生成时间:2017-11-23 17:46:19 by ebs-core  
CREATE  procedure order_191_modify_2(
@ord2id bigint, 
@cmpid int, 
@branchid bigint, 
@userdpid bigint, 
@userotid bigint, 
@useruid int, 
@jbid bigint, 
@ordid bigint, 
@ord2tag int, @ord2_fbizid int,@ord2_ford2tag int,@ord2_jhbz int,@ord2_order int,@ord2_rbizid int,@ord2_rord2tag int,@ord2_zbrs int,@ord2_fatherord2id bigint,@ord2_ford2id bigint,@ord2_fordid bigint,@ord2_rord2id bigint,@ord2_rordid bigint,@ord2_code varchar(50),@ord2_ftype varchar(10),@ord2_key varchar(30),@ord2_rtype varchar(10),@ord2_tags varchar(100),@ord2_bmmc nvarchar(100),@ord2_bz nvarchar(100),@ord2_caption nvarchar(100),@ord2_gw nvarchar(100),@ord2_status nvarchar(30) ) 
as  
begin  
set nocount on  
declare @nonedate datetime 
set @nonedate = CONVERT(datetime,'1910-1-1')
declare @ord2group2 nvarchar(50) 
set @ord2group2 = '' 
declare @sys_recid bigint 
set @sys_recid = 0 
 declare @operation varchar(50)
 declare @errorinfo nvarchar(4000) 
 set @operation = 'continue' 
set @errorinfo = '' 
 --- 以下是预处理事件中的临时表
 exec drop_temp_table '#old' select * into #old from order_191_2 where ord2_id=@ord2id exec drop_temp_table '#new' select * ,null recid into #new from #old update #new set ord2_fbizid=case when @ord2_fbizid is null or @ord2_fbizid = -999999999  then ord2_fbizid else @ord2_fbizid end,ord2_ford2tag=case when @ord2_ford2tag is null or @ord2_ford2tag = -999999999  then ord2_ford2tag else @ord2_ford2tag end,ord2_jhbz=case when @ord2_jhbz is null or @ord2_jhbz = -999999999  then ord2_jhbz else @ord2_jhbz end,ord2_order=case when @ord2_order is null or @ord2_order = -999999999  then ord2_order else @ord2_order end,ord2_rbizid=case when @ord2_rbizid is null or @ord2_rbizid = -999999999  then ord2_rbizid else @ord2_rbizid end,ord2_rord2tag=case when @ord2_rord2tag is null or @ord2_rord2tag = -999999999  then ord2_rord2tag else @ord2_rord2tag end,ord2_zbrs=case when @ord2_zbrs is null or @ord2_zbrs = -999999999  then ord2_zbrs else @ord2_zbrs end,ord2_fatherord2id=case when @ord2_fatherord2id is null or @ord2_fatherord2id = -999999999  then ord2_fatherord2id else @ord2_fatherord2id end,ord2_ford2id=case when @ord2_ford2id is null or @ord2_ford2id = -999999999  then ord2_ford2id else @ord2_ford2id end,ord2_fordid=case when @ord2_fordid is null or @ord2_fordid = -999999999  then ord2_fordid else @ord2_fordid end,ord2_rord2id=case when @ord2_rord2id is null or @ord2_rord2id = -999999999  then ord2_rord2id else @ord2_rord2id end,ord2_rordid=case when @ord2_rordid is null or @ord2_rordid = -999999999  then ord2_rordid else @ord2_rordid end,ord2_code=case when @ord2_code is null or @ord2_code = '_none_'  then ord2_code else @ord2_code end,ord2_ftype=case when @ord2_ftype is null or @ord2_ftype = '_none_'  then ord2_ftype else @ord2_ftype end,ord2_key=case when @ord2_key is null or @ord2_key = '_none_'  then ord2_key else @ord2_key end,ord2_rtype=case when @ord2_rtype is null or @ord2_rtype = '_none_'  then ord2_rtype else @ord2_rtype end,ord2_tags=case when @ord2_tags is null or @ord2_tags = '_none_'  then ord2_tags else @ord2_tags end,ord2_bmmc=case when @ord2_bmmc is null or @ord2_bmmc = '_none_'  then ord2_bmmc else @ord2_bmmc end,ord2_bz=case when @ord2_bz is null or @ord2_bz = '_none_'  then ord2_bz else @ord2_bz end,ord2_caption=case when @ord2_caption is null or @ord2_caption = '_none_'  then ord2_caption else @ord2_caption end,ord2_gw=case when @ord2_gw is null or @ord2_gw = '_none_'  then ord2_gw else @ord2_gw end,ord2_status=case when @ord2_status is null or @ord2_status = '_none_'  then ord2_status else @ord2_status endupdate #new set recid=ord2_id  alter table new add default '' for ord2_fbizid   alter table new add default '' for ord2_ford2tag   alter table new add default '' for ord2_jhbz   alter table new add default '' for ord2_order   alter table new add default '' for ord2_rbizid   alter table new add default '' for ord2_rord2tag   alter table new add default '' for ord2_tag   alter table new add default '' for ord2_zbrs   alter table new add default '' for ord2_date   alter table new add default '' for ord2_updated   alter table new add default '' for ord2_fatherord2id   alter table new add default '' for ord2_ford2id   alter table new add default '' for ord2_fordid   alter table new add default '' for ord2_ordid   alter table new add default '' for ord2_rord2id   alter table new add default '' for ord2_rordid   alter table new add default '' for ord2_code   alter table new add default '' for ord2_ftype   alter table new add default '' for ord2_key   alter table new add default '' for ord2_rtype   alter table new add default '' for ord2_tags   alter table new add default '' for ord2_bmmc   alter table new add default '' for ord2_bz   alter table new add default '' for ord2_caption   alter table new add default '' for ord2_group   alter table new add default '' for ord2_gw   alter table new add default '' for ord2_status exec order_191_modify_2_before @cmpid,@branchid,@userdpid,@useruid,@userotid,@jbid,@ordid,@ord2tag,@ord2id,@operation output,@errorinfo output 
 if (@operation='continue') 
 begin
 set @nonedate=@nonedate   -- here useless 
  set @ord2group2=''  select top 1 @ord2group2=ord2_group from #new where ord2_group>''  set @ord2group2 = isnull(@ord2group2 , '')  insert into order_191_2(ord2_date,ord2_updated,ord2_tag,ord2_group,ord2_ordid,ord2_fbizid,ord2_ford2tag,ord2_jhbz,ord2_order,ord2_rbizid,ord2_rord2tag,ord2_zbrs,ord2_fatherord2id,ord2_ford2id,ord2_fordid,ord2_rord2id,ord2_rordid,ord2_code,ord2_ftype,ord2_key,ord2_rtype,ord2_tags,ord2_bmmc,ord2_bz,ord2_caption,ord2_gw,ord2_status)  select case when new.ord2_date>getdate()-40000 then new.ord2_date else getdate() end ,getdate(),2,    case when new.ord2_group>'' then new.ord2_group else @ord2group2 end , @ordid,new.ord2_fbizid,new.ord2_ford2tag,new.ord2_jhbz,new.ord2_order,new.ord2_rbizid,new.ord2_rord2tag,new.ord2_zbrs,new.ord2_fatherord2id,new.ord2_ford2id,new.ord2_fordid,new.ord2_rord2id,new.ord2_rordid,new.ord2_code,new.ord2_ftype,new.ord2_key,new.ord2_rtype,new.ord2_tags,new.ord2_bmmc,new.ord2_bz,new.ord2_caption,new.ord2_gw,new.ord2_status from #new new where recid is null update  old set ord2_fbizid=case when new.ord2_fbizid is null or new.ord2_fbizid = -999999999  then old.ord2_fbizid else new.ord2_fbizid end,ord2_ford2tag=case when new.ord2_ford2tag is null or new.ord2_ford2tag = -999999999  then old.ord2_ford2tag else new.ord2_ford2tag end,ord2_jhbz=case when new.ord2_jhbz is null or new.ord2_jhbz = -999999999  then old.ord2_jhbz else new.ord2_jhbz end,ord2_order=case when new.ord2_order is null or new.ord2_order = -999999999  then old.ord2_order else new.ord2_order end,ord2_rbizid=case when new.ord2_rbizid is null or new.ord2_rbizid = -999999999  then old.ord2_rbizid else new.ord2_rbizid end,ord2_rord2tag=case when new.ord2_rord2tag is null or new.ord2_rord2tag = -999999999  then old.ord2_rord2tag else new.ord2_rord2tag end,ord2_zbrs=case when new.ord2_zbrs is null or new.ord2_zbrs = -999999999  then old.ord2_zbrs else new.ord2_zbrs end,ord2_fatherord2id=case when new.ord2_fatherord2id is null or new.ord2_fatherord2id = -999999999  then old.ord2_fatherord2id else new.ord2_fatherord2id end,ord2_ford2id=case when new.ord2_ford2id is null or new.ord2_ford2id = -999999999  then old.ord2_ford2id else new.ord2_ford2id end,ord2_fordid=case when new.ord2_fordid is null or new.ord2_fordid = -999999999  then old.ord2_fordid else new.ord2_fordid end,ord2_rord2id=case when new.ord2_rord2id is null or new.ord2_rord2id = -999999999  then old.ord2_rord2id else new.ord2_rord2id end,ord2_rordid=case when new.ord2_rordid is null or new.ord2_rordid = -999999999  then old.ord2_rordid else new.ord2_rordid end,ord2_code=case when new.ord2_code is null or new.ord2_code = '_none_'  then old.ord2_code else new.ord2_code end,ord2_ftype=case when new.ord2_ftype is null or new.ord2_ftype = '_none_'  then old.ord2_ftype else new.ord2_ftype end,ord2_key=case when new.ord2_key is null or new.ord2_key = '_none_'  then old.ord2_key else new.ord2_key end,ord2_rtype=case when new.ord2_rtype is null or new.ord2_rtype = '_none_'  then old.ord2_rtype else new.ord2_rtype end,ord2_tags=case when new.ord2_tags is null or new.ord2_tags = '_none_'  then old.ord2_tags else new.ord2_tags end,ord2_bmmc=case when new.ord2_bmmc is null or new.ord2_bmmc = '_none_'  then old.ord2_bmmc else new.ord2_bmmc end,ord2_bz=case when new.ord2_bz is null or new.ord2_bz = '_none_'  then old.ord2_bz else new.ord2_bz end,ord2_caption=case when new.ord2_caption is null or new.ord2_caption = '_none_'  then old.ord2_caption else new.ord2_caption end,ord2_gw=case when new.ord2_gw is null or new.ord2_gw = '_none_'  then old.ord2_gw else new.ord2_gw end,ord2_status=case when new.ord2_status is null or new.ord2_status = '_none_'  then old.ord2_status else new.ord2_status end,ord2_updated=getdate() from order_191_2 old,#new new where old.ord2_id=new.ord2_id and (new.recid is not null) exec order_191_modify_2_after @cmpid ,@branchid ,@userdpid,@useruid,@userotid,@jbid,@ordid,@ord2tag,@ord2id  set @ord2group2=''  select top 1 @ord2group2=ord2_group from #new where ord2_group>''  set @ord2group2 = isnull(@ord2group2 , '')  insert into order_191_2(ord2_date,ord2_updated,ord2_tag,ord2_group,ord2_ordid,ord2_fbizid,ord2_ford2tag,ord2_jhbz,ord2_order,ord2_rbizid,ord2_rord2tag,ord2_zbrs,ord2_fatherord2id,ord2_ford2id,ord2_fordid,ord2_rord2id,ord2_rordid,ord2_code,ord2_ftype,ord2_key,ord2_rtype,ord2_tags,ord2_bmmc,ord2_bz,ord2_caption,ord2_gw,ord2_status)  select case when new.ord2_date>getdate()-40000 then new.ord2_date else getdate() end ,getdate(),2,    case when new.ord2_group>'' then new.ord2_group else @ord2group2 end , @ordid,new.ord2_fbizid,new.ord2_ford2tag,new.ord2_jhbz,new.ord2_order,new.ord2_rbizid,new.ord2_rord2tag,new.ord2_zbrs,new.ord2_fatherord2id,new.ord2_ford2id,new.ord2_fordid,new.ord2_rord2id,new.ord2_rordid,new.ord2_code,new.ord2_ftype,new.ord2_key,new.ord2_rtype,new.ord2_tags,new.ord2_bmmc,new.ord2_bz,new.ord2_caption,new.ord2_gw,new.ord2_status from #new new where recid is null 
 select 'ok' operation, '' errorinfo 
end  else 
begin
select @operation operation, @errorinfo errorinfo  
end
exec drop_temp_table '#new' exec drop_temp_table '#old' set nocount off 
end