IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_customer_newcst_before]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_customer_newcst_before]
GO
-- 生成时间:2018-06-13 15:26:44 by ebs-core  
create  procedure [dbo].[mps_customer_newcst_before](
     @cmpid int,
     @branchid int,
     @userdpid int,
     @useruid int,
     @userotid int,
     @ccid 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 @newccid bigint  
declare @sccids table(ccid bigint)  
 set @newccid = @ccid  
 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 @sccids ( ccid ) 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 @sccids ( ccid ) 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 @sccids ( ccid ) values ( convert ( bigint , @ordid_s ) )  
 break  
 end  
 end  
 end 
 set @operation = 'continue'
 set @errorinfo = '' 
 --- 以下是预处理事件中的临时表
 
exec drop_temp_table '#new' 
select * ,'' sourcefield  into #new from mps_customer where cc_id=@newccid 
 ---- 以下是开发人员写的 before new order 事件 --------------
 
--#master--#master--#master--#master--#master--#master--#master--#master--#master--#master--#master--#master
-- update #new 
 ---- 以上是开发人员写的 before new order 事件 --------------
 
 if (@operation='continue') 
 begin
 set @nonedate = @nonedate 
 
update old set 
cc_branch=case when new.cc_branch is null or new.cc_branch = '_none_'  then old.cc_branch else new.cc_branch end,cc_dpid=case when new.cc_dpid is null or new.cc_dpid = -999999999  then old.cc_dpid else new.cc_dpid end,cc_depart=case when new.cc_depart is null or new.cc_depart = '_none_'  then old.cc_depart else new.cc_depart end,cc_cuid=case when new.cc_cuid is null or new.cc_cuid = -999999999  then old.cc_cuid else new.cc_cuid end,cc_cuname=case when new.cc_cuname is null or new.cc_cuname = '_none_'  then old.cc_cuname else new.cc_cuname end,cc_caption=case when new.cc_caption is null or new.cc_caption = '_none_'  then old.cc_caption else new.cc_caption end,cc_type=case when new.cc_type is null or new.cc_type = '_none_'  then old.cc_type else new.cc_type end,cc_code=case when new.cc_code is null or new.cc_code = '_none_'  then old.cc_code else new.cc_code end,cc_createdpid=case when new.cc_createdpid is null or new.cc_createdpid = -999999999  then old.cc_createdpid else new.cc_createdpid end,cc_createdepart=case when new.cc_createdepart is null or new.cc_createdepart = '_none_'  then old.cc_createdepart else new.cc_createdepart end,cc_createcuid=case when new.cc_createcuid is null or new.cc_createcuid = -999999999  then old.cc_createcuid else new.cc_createcuid end,cc_creator=case when new.cc_creator is null or new.cc_creator = '_none_'  then old.cc_creator else new.cc_creator end,cc_name=case when new.cc_name is null or new.cc_name = '_none_'  then old.cc_name else new.cc_name end,cc_company=case when new.cc_company is null or new.cc_company = '_none_'  then old.cc_company else new.cc_company end,cc_gender=case when new.cc_gender is null or new.cc_gender = -999999999  then old.cc_gender else new.cc_gender end,cc_mobile=case when new.cc_mobile is null or new.cc_mobile = '_none_'  then old.cc_mobile else new.cc_mobile end,cc_contact=case when new.cc_contact is null or new.cc_contact = '_none_'  then old.cc_contact else new.cc_contact end,cc_icon=case when new.cc_icon is null or new.cc_icon = '_none_'  then old.cc_icon else new.cc_icon end,cc_fccid=case when new.cc_fccid is null or new.cc_fccid = -999999999  then old.cc_fccid else new.cc_fccid end,cc_province=case when new.cc_province is null or new.cc_province = '_none_'  then old.cc_province else new.cc_province end,cc_municipal=case when new.cc_municipal is null or new.cc_municipal = '_none_'  then old.cc_municipal else new.cc_municipal end,cc_county=case when new.cc_county is null or new.cc_county = '_none_'  then old.cc_county else new.cc_county end,cc_title=case when new.cc_title is null or new.cc_title = '_none_'  then old.cc_title else new.cc_title end,cc_prof=case when new.cc_prof is null or new.cc_prof = '_none_'  then old.cc_prof else new.cc_prof end,cc_native=case when new.cc_native is null or new.cc_native = '_none_'  then old.cc_native else new.cc_native end,cc_college=case when new.cc_college is null or new.cc_college = '_none_'  then old.cc_college else new.cc_college end,cc_taboos=case when new.cc_taboos is null or new.cc_taboos = '_none_'  then old.cc_taboos else new.cc_taboos end,cc_addr=case when new.cc_addr is null or new.cc_addr = '_none_'  then old.cc_addr else new.cc_addr end,cc_post=case when new.cc_post is null or new.cc_post = '_none_'  then old.cc_post else new.cc_post end,cc_source=case when new.cc_source is null or new.cc_source = '_none_'  then old.cc_source else new.cc_source end,cc_site=case when new.cc_site is null or new.cc_site = '_none_'  then old.cc_site else new.cc_site end,cc_email=case when new.cc_email is null or new.cc_email = '_none_'  then old.cc_email else new.cc_email end,cc_msnqq=case when new.cc_msnqq is null or new.cc_msnqq = '_none_'  then old.cc_msnqq else new.cc_msnqq end,cc_status=case when new.cc_status is null or new.cc_status = '_none_'  then old.cc_status else new.cc_status end,cc_health=case when new.cc_health is null or new.cc_health = -999999999  then old.cc_health else new.cc_health end,cc_score=case when new.cc_score is null or new.cc_score = -999999999  then old.cc_score else new.cc_score end,cc_total=case when new.cc_total is null or new.cc_total = -999999999  then old.cc_total else new.cc_total end,cc_value=case when new.cc_value is null or new.cc_value = -999999999  then old.cc_value else new.cc_value end,cc_prev=case when new.cc_prev is null or new.cc_prev = -999999999  then old.cc_prev else new.cc_prev end,cc_rear=case when new.cc_rear is null or new.cc_rear = -999999999  then old.cc_rear else new.cc_rear end,cc_allowlogin=case when new.cc_allowlogin is null or new.cc_allowlogin = -999999999  then old.cc_allowlogin else new.cc_allowlogin end,cc_other=case when new.cc_other is null or new.cc_other = '_none_'  then old.cc_other else new.cc_other end,cc_birth=case when new.cc_birth is null or new.cc_birth = @nonedate then old.cc_birth else new.cc_birth end,cc_monthday=case when new.cc_monthday is null or new.cc_monthday = '_none_'  then old.cc_monthday else new.cc_monthday end,cc_creditquantum=case when new.cc_creditquantum is null or new.cc_creditquantum = -999999999  then old.cc_creditquantum else new.cc_creditquantum end,cc_accountperiod=case when new.cc_accountperiod is null or new.cc_accountperiod = -999999999  then old.cc_accountperiod else new.cc_accountperiod end,cc_use=case when new.cc_use is null or new.cc_use = -999999999  then old.cc_use else new.cc_use end,cc_identtype=case when new.cc_identtype is null or new.cc_identtype = '_none_'  then old.cc_identtype else new.cc_identtype end,cc_identno=case when new.cc_identno is null or new.cc_identno = '_none_'  then old.cc_identno else new.cc_identno end,cc_dsa=case when new.cc_dsa is null or new.cc_dsa = '_none_'  then old.cc_dsa else new.cc_dsa end,cc_cds=case when new.cc_cds is null or new.cc_cds = '_none_'  then old.cc_cds else new.cc_cds end,cc_security=case when new.cc_security is null or new.cc_security = -999999999  then old.cc_security else new.cc_security end,cc_aaaaa=case when new.cc_aaaaa is null or new.cc_aaaaa = '_none_'  then old.cc_aaaaa else new.cc_aaaaa end,cc_dqqqsa=case when new.cc_dqqqsa is null or new.cc_dqqqsa = '_none_'  then old.cc_dqqqsa else new.cc_dqqqsa end,cc_dqqsa=case when new.cc_dqqsa is null or new.cc_dqqsa = '_none_'  then old.cc_dqqsa else new.cc_dqqsa end,cc_opod=case when new.cc_opod is null or new.cc_opod = '_none_'  then old.cc_opod else new.cc_opod end,cc_posid=case when new.cc_posid is null or new.cc_posid = '_none_'  then old.cc_posid else new.cc_posid end,cc_p1osid=case when new.cc_p1osid is null or new.cc_p1osid = '_none_'  then old.cc_p1osid else new.cc_p1osid end
from mps_customer old , #new new  where old.cc_id=new.cc_id 

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

set nocount off 
end