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

-- 生成时间:2018-05-03 16:37:31 by ebs-core  
CREATE  procedure order_108_newbiz_before(
     @cmpid int,
     @branchid int,
     @userdpid int,
     @useruid int,
     @userotid int,
     @jbid bigint,
     @ordid bigint,
     @stype varchar(20),
     @sbizid int,
     @sord2tag int,
     @sord2id bigint,
     @sordidstr varchar(max),
     @extparam1 nvarchar(1000),
     @extparam2 nvarchar(1000),
     @extparam3 nvarchar(1000),
     @operation varchar(50) output,
     @errorinfo nvarchar(4000) output
  ) 
as  
begin  
set nocount on  
if ((@extparam1 is null) or (@extparam1='_none_'))  set @extparam1 = '' 
  if ((@extparam2 is null) or (@extparam2='_none_'))  set @extparam2 = '' 
  if ((@extparam3 is null) or (@extparam3='_none_'))  set @extparam3 = '' 
declare @ord2group2 nvarchar(50) 
set @ord2group2 = '' 
declare @sys_recid bigint 
set @sys_recid = 0 
declare @newordid bigint  
declare @sordids table(ordid bigint)  
 set @newordid = @ordid  
 declare @i int , @curInd int , @strlen int , @ordid_s varchar ( 20 )  
 declare @sordid bigint  
 set @sordid = 0  
 declare @nonedate datetime 
set @nonedate = CONVERT(datetime,'1910-1-1')
 if ( charindex ( ',' ,@sordidstr ) = 0 and @sordidstr > '' )  
 begin  
 set @sordid = convert ( bigint ,@sordidstr )  
 insert into @sordids ( ordid ) values ( @sordid )  
 end   
 else 
 begin  
 select @curInd = 1 , @strlen = LEN ( @sordidstr )  
 while ( @curInd <= @strlen )  
 begin  
 select @i = charindex ( ',' ,@sordidstr , @curInd )  
 if ( @i > 0 )  
 begin  
 select @ordid_s = SUBSTRING ( @sordidstr , @curInd , @i  - @curInd )  
 insert into @sordids ( ordid ) values ( convert ( bigint , @ordid_s ) )  
 set @curInd = @i  + 1  
 end  
 else if ( @curInd <= @strlen )  
 begin  
 select @ordid_s = SUBSTRING ( @sordidstr , @curInd , @strlen  - @curInd  + 1 )  
 insert into @sordids ( ordid ) values ( convert ( bigint , @ordid_s ) )  
 break  
 end  
 end  
 end 
 set @operation = 'continue'
 set @errorinfo = '' 
 --- 以下是预处理事件中的临时表
 
exec drop_temp_table '#new' 
select * into #new from order_108 where ord_id=@newordid 
 ---- 以下是开发人员写的 before new order 事件 --------------
 declare @key1 int
select @key1 = ord_fbizid from #new 

if @key1=99
    begin
        update n
        set n.ord_kysj = r.ord_ykysj,
            n.ord_lxdh = r.ord_lxfs
        from #new n,order_99 r
        where n.ord_fordid = r.ord_id 
    end
else
if @key1=113
    begin
        update n
            set n.ord_kysj = r.ord_ykysj,
                n.ord_lxdh = r.ord_lxfs1,
                n.ord_dpfzr = r.ord_dpfzr1,
                n.ord_dpmc = r.ord_mbdp,
                n.ord_dpdz = r.ord_mddpdz
            from #new n,order_113 r
            where n.ord_fordid = r.ord_id 
    end
else
if @key1 =116
    begin
        update n
        set n.ord_kysj = r.ord_ykysj,
            n.ord_lxdh = r.ord_lxfs
        from #new n,order_116 r
        where n.ord_fordid = r.ord_id 
    end
 ---- 以上是开发人员写的 before new order 事件 --------------
 
 if (@operation='continue') 
 begin
 set @nonedate = @nonedate 
 
update old set 
ord_createcuid=case when new.ord_createcuid is null or new.ord_createcuid = -999999999  then old.ord_createcuid else new.ord_createcuid end,ord_createdpid=case when new.ord_createdpid is null or new.ord_createdpid = -999999999  then old.ord_createdpid else new.ord_createdpid end,ord_cuid=case when new.ord_cuid is null or new.ord_cuid = -999999999  then old.ord_cuid else new.ord_cuid end,ord_dpid=case when new.ord_dpid is null or new.ord_dpid = -999999999  then old.ord_dpid else new.ord_dpid end,ord_fbizid=case when new.ord_fbizid is null or new.ord_fbizid = -999999999  then old.ord_fbizid else new.ord_fbizid end,ord_ford2tag=case when new.ord_ford2tag is null or new.ord_ford2tag = -999999999  then old.ord_ford2tag else new.ord_ford2tag end,ord_noi=case when new.ord_noi is null or new.ord_noi = -999999999  then old.ord_noi else new.ord_noi end,ord_rbizid=case when new.ord_rbizid is null or new.ord_rbizid = -999999999  then old.ord_rbizid else new.ord_rbizid end,ord_rord2tag=case when new.ord_rord2tag is null or new.ord_rord2tag = -999999999  then old.ord_rord2tag else new.ord_rord2tag end,ord_security=case when new.ord_security is null or new.ord_security = -999999999  then old.ord_security else new.ord_security end,ord_style=case when new.ord_style is null or new.ord_style = -999999999  then old.ord_style else new.ord_style end,ord_templateid=case when new.ord_templateid is null or new.ord_templateid = -999999999  then old.ord_templateid else new.ord_templateid end,ord_enddate=case when new.ord_enddate is null or new.ord_enddate = @nonedate then old.ord_enddate else new.ord_enddate end,ord_kysj=case when new.ord_kysj is null or new.ord_kysj = @nonedate then old.ord_kysj else new.ord_kysj end,ord_cbid=case when new.ord_cbid is null or new.ord_cbid = -999999999  then old.ord_cbid else new.ord_cbid end,ord_fjbid=case when new.ord_fjbid is null or new.ord_fjbid = -999999999  then old.ord_fjbid else new.ord_fjbid end,ord_ford2id=case when new.ord_ford2id is null or new.ord_ford2id = -999999999  then old.ord_ford2id else new.ord_ford2id end,ord_fordid=case when new.ord_fordid is null or new.ord_fordid = -999999999  then old.ord_fordid else new.ord_fordid end,ord_rord2id=case when new.ord_rord2id is null or new.ord_rord2id = -999999999  then old.ord_rord2id else new.ord_rord2id end,ord_rordid=case when new.ord_rordid is null or new.ord_rordid = -999999999  then old.ord_rordid else new.ord_rordid end,ord_ddcuid=case when new.ord_ddcuid is null or new.ord_ddcuid = -999999999  then old.ord_ddcuid else new.ord_ddcuid end,ord_ddid=case when new.ord_ddid is null or new.ord_ddid = -999999999  then old.ord_ddid else new.ord_ddid end,ord_ftype=case when new.ord_ftype is null or new.ord_ftype = '_none_'  then old.ord_ftype else new.ord_ftype end,ord_key=case when new.ord_key is null or new.ord_key = '_none_'  then old.ord_key else new.ord_key end,ord_no=case when new.ord_no is null or new.ord_no = '_none_'  then old.ord_no else new.ord_no end,ord_rtype=case when new.ord_rtype is null or new.ord_rtype = '_none_'  then old.ord_rtype else new.ord_rtype end,ord_branch=case when new.ord_branch is null or new.ord_branch = '_none_'  then old.ord_branch else new.ord_branch end,ord_bz=case when new.ord_bz is null or new.ord_bz = '_none_'  then old.ord_bz else new.ord_bz end,ord_bz1=case when new.ord_bz1 is null or new.ord_bz1 = '_none_'  then old.ord_bz1 else new.ord_bz1 end,ord_createbizids=case when new.ord_createbizids is null or new.ord_createbizids = '_none_'  then old.ord_createbizids else new.ord_createbizids end,ord_createdepart=case when new.ord_createdepart is null or new.ord_createdepart = '_none_'  then old.ord_createdepart else new.ord_createdepart end,ord_creator=case when new.ord_creator is null or new.ord_creator = '_none_'  then old.ord_creator else new.ord_creator end,ord_zw=case when new.ord_zw is null or new.ord_zw = '_none_'  then old.ord_zw else new.ord_zw end,ord_ywlx=case when new.ord_ywlx is null or new.ord_ywlx = '_none_'  then old.ord_ywlx else new.ord_ywlx end,ord_wz03=case when new.ord_wz03 is null or new.ord_wz03 = '_none_'  then old.ord_wz03 else new.ord_wz03 end,ord_wz04=case when new.ord_wz04 is null or new.ord_wz04 = '_none_'  then old.ord_wz04 else new.ord_wz04 end,ord_wz05=case when new.ord_wz05 is null or new.ord_wz05 = '_none_'  then old.ord_wz05 else new.ord_wz05 end,ord_zj=case when new.ord_zj is null or new.ord_zj = '_none_'  then old.ord_zj else new.ord_zj end,ord_ddry=case when new.ord_ddry is null or new.ord_ddry = '_none_'  then old.ord_ddry else new.ord_ddry end,ord_lxfs1=case when new.ord_lxfs1 is null or new.ord_lxfs1 = '_none_'  then old.ord_lxfs1 else new.ord_lxfs1 end,ord_syryms=case when new.ord_syryms is null or new.ord_syryms = '_none_'  then old.ord_syryms else new.ord_syryms end,ord_template=case when new.ord_template is null or new.ord_template = '_none_'  then old.ord_template else new.ord_template end,ord_title=case when new.ord_title is null or new.ord_title = '_none_'  then old.ord_title else new.ord_title end,ord_type=case when new.ord_type is null or new.ord_type = '_none_'  then old.ord_type else new.ord_type end,ord_wz01=case when new.ord_wz01 is null or new.ord_wz01 = '_none_'  then old.ord_wz01 else new.ord_wz01 end,ord_wz02=case when new.ord_wz02 is null or new.ord_wz02 = '_none_'  then old.ord_wz02 else new.ord_wz02 end,ord_ky15=case when new.ord_ky15 is null or new.ord_ky15 = '_none_'  then old.ord_ky15 else new.ord_ky15 end,ord_ky16=case when new.ord_ky16 is null or new.ord_ky16 = '_none_'  then old.ord_ky16 else new.ord_ky16 end,ord_ky17=case when new.ord_ky17 is null or new.ord_ky17 = '_none_'  then old.ord_ky17 else new.ord_ky17 end,ord_ky18=case when new.ord_ky18 is null or new.ord_ky18 = '_none_'  then old.ord_ky18 else new.ord_ky18 end,ord_lxdh=case when new.ord_lxdh is null or new.ord_lxdh = '_none_'  then old.ord_lxdh else new.ord_lxdh end,ord_status=case when new.ord_status is null or new.ord_status = '_none_'  then old.ord_status else new.ord_status end,ord_ky09=case when new.ord_ky09 is null or new.ord_ky09 = '_none_'  then old.ord_ky09 else new.ord_ky09 end,ord_ky10=case when new.ord_ky10 is null or new.ord_ky10 = '_none_'  then old.ord_ky10 else new.ord_ky10 end,ord_ky11=case when new.ord_ky11 is null or new.ord_ky11 = '_none_'  then old.ord_ky11 else new.ord_ky11 end,ord_ky12=case when new.ord_ky12 is null or new.ord_ky12 = '_none_'  then old.ord_ky12 else new.ord_ky12 end,ord_ky13=case when new.ord_ky13 is null or new.ord_ky13 = '_none_'  then old.ord_ky13 else new.ord_ky13 end,ord_ky14=case when new.ord_ky14 is null or new.ord_ky14 = '_none_'  then old.ord_ky14 else new.ord_ky14 end,ord_ky03=case when new.ord_ky03 is null or new.ord_ky03 = '_none_'  then old.ord_ky03 else new.ord_ky03 end,ord_ky04=case when new.ord_ky04 is null or new.ord_ky04 = '_none_'  then old.ord_ky04 else new.ord_ky04 end,ord_ky05=case when new.ord_ky05 is null or new.ord_ky05 = '_none_'  then old.ord_ky05 else new.ord_ky05 end,ord_ky06=case when new.ord_ky06 is null or new.ord_ky06 = '_none_'  then old.ord_ky06 else new.ord_ky06 end,ord_ky07=case when new.ord_ky07 is null or new.ord_ky07 = '_none_'  then old.ord_ky07 else new.ord_ky07 end,ord_ky08=case when new.ord_ky08 is null or new.ord_ky08 = '_none_'  then old.ord_ky08 else new.ord_ky08 end,ord_jc03=case when new.ord_jc03 is null or new.ord_jc03 = '_none_'  then old.ord_jc03 else new.ord_jc03 end,ord_jc04=case when new.ord_jc04 is null or new.ord_jc04 = '_none_'  then old.ord_jc04 else new.ord_jc04 end,ord_jc05=case when new.ord_jc05 is null or new.ord_jc05 = '_none_'  then old.ord_jc05 else new.ord_jc05 end,ord_jyfk=case when new.ord_jyfk is null or new.ord_jyfk = '_none_'  then old.ord_jyfk else new.ord_jyfk end,ord_ky01=case when new.ord_ky01 is null or new.ord_ky01 = '_none_'  then old.ord_ky01 else new.ord_ky01 end,ord_ky02=case when new.ord_ky02 is null or new.ord_ky02 = '_none_'  then old.ord_ky02 else new.ord_ky02 end,ord_empname=case when new.ord_empname is null or new.ord_empname = '_none_'  then old.ord_empname else new.ord_empname end,ord_hg01=case when new.ord_hg01 is null or new.ord_hg01 = '_none_'  then old.ord_hg01 else new.ord_hg01 end,ord_hg02=case when new.ord_hg02 is null or new.ord_hg02 = '_none_'  then old.ord_hg02 else new.ord_hg02 end,ord_hg03=case when new.ord_hg03 is null or new.ord_hg03 = '_none_'  then old.ord_hg03 else new.ord_hg03 end,ord_jc01=case when new.ord_jc01 is null or new.ord_jc01 = '_none_'  then old.ord_jc01 else new.ord_jc01 end,ord_jc02=case when new.ord_jc02 is null or new.ord_jc02 = '_none_'  then old.ord_jc02 else new.ord_jc02 end,ord_depart=case when new.ord_depart is null or new.ord_depart = '_none_'  then old.ord_depart else new.ord_depart end,ord_dpbh=case when new.ord_dpbh is null or new.ord_dpbh = '_none_'  then old.ord_dpbh else new.ord_dpbh end,ord_dpdz=case when new.ord_dpdz is null or new.ord_dpdz = '_none_'  then old.ord_dpdz else new.ord_dpdz end,ord_dpfzr=case when new.ord_dpfzr is null or new.ord_dpfzr = '_none_'  then old.ord_dpfzr else new.ord_dpfzr end,ord_dplx=case when new.ord_dplx is null or new.ord_dplx = '_none_'  then old.ord_dplx else new.ord_dplx end,ord_dpmc=case when new.ord_dpmc is null or new.ord_dpmc = '_none_'  then old.ord_dpmc else new.ord_dpmc end
from order_108 old , #new new  where old.ord_id=new.ord_id 

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

set nocount off 
end