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

-- 生成时间:2018-05-02 17:22:33 by ebs-core  
CREATE  procedure order_90_2_newdetail_before(
     @cmpid int,
     @branchid int,
     @userdpid int,
     @useruid int,
     @userotid int,
     @jbid bigint,
     @ordid bigint,
     @ord2tag int,
     @ord2group nvarchar(50),
     @ord2id bigint,
     @operation varchar(50) output ,
     @errorinfo nvarchar(4000) output
  ) 
as  
begin  
set nocount on  
declare @sys_recid bigint 
set @sys_recid = 0 
declare @ord2group2 nvarchar(50) 
set @ord2group2 = '' 
 declare @nonedate datetime 
set @nonedate = CONVERT(datetime,'1910-1-1')
 set @operation = 'continue'
 set @errorinfo = '' 
 --- 以下是预处理事件中的临时表
 ---   #new 在主体中已经生成
 
exec drop_temp_table '#romaster' 
select * into #romaster from order_90 where ord_id=@ordid 
 ---- 以下是开发人员写的 before new details order 事件 --------------
 update #new
set ord2_fordid= ord_fordid
from #romaster 


 ---- 以上是开发人员写的 before new details order 事件 --------------
 
 if (@operation='continue') 
 begin
 set @nonedate =  @nonedate  -- here useless 
 
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_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_jssj=case when new.ord2_jssj is null or new.ord2_jssj = @nonedate then old.ord2_jssj else new.ord2_jssj end,ord2_kssj=case when new.ord2_kssj is null or new.ord2_kssj = @nonedate then old.ord2_kssj else new.ord2_kssj 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_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_group=case when new.ord2_group is null or new.ord2_group = '_none_'  then old.ord2_group else new.ord2_group 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_xclx=case when new.ord2_xclx is null or new.ord2_xclx = '_none_'  then old.ord2_xclx else new.ord2_xclx end,ord2_xcmdd=case when new.ord2_xcmdd is null or new.ord2_xcmdd = '_none_'  then old.ord2_xcmdd else new.ord2_xcmdd end,ord2_xcms=case when new.ord2_xcms is null or new.ord2_xcms = '_none_'  then old.ord2_xcms else new.ord2_xcms end,ord2_dpbh=case when new.ord2_dpbh is null or new.ord2_dpbh = '_none_'  then old.ord2_dpbh else new.ord2_dpbh end
from order_90_2 old , #new new  
where old.ord2_id=new.ord2_id and (new.recid is not null)  

end 
--- 清除临时表 
exec drop_temp_table '#romaster' 

set nocount off 
end