IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_customer_modify]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_customer_modify]
GO
-- 生成时间:2018-06-13 15:26:43 by ebs-core  
CREATE  procedure [dbo].[mps_customer_modify](
@cmpid int,
@branchid int,
@userdpid int,
@useruid int,
@userotid int,
@ccid bigint,@sourcefield varchar(50)=default, 
@cc_dpid int =default ,@cc_cuid int =default ,@cc_createdpid int =default ,@cc_createcuid int =default ,@cc_gender int =default ,@cc_fccid int =default ,@cc_allowlogin int =default ,@cc_creditquantum int =default ,@cc_accountperiod int =default ,@cc_use int =default ,@cc_security int =default ,@cc_birth datetime =default ,@cc_health decimal(18,2) =default ,@cc_score decimal(18,4) =default ,@cc_total decimal(18,4) =default ,@cc_value decimal(18,4) =default ,@cc_prev decimal(18,4) =default ,@cc_rear decimal(18,4) =default ,@cc_mobile varchar(18) =default ,@cc_contact varchar(50) =default ,@cc_icon varchar(50) =default ,@cc_title varchar(20) =default ,@cc_prof varchar(20) =default ,@cc_post varchar(6) =default ,@cc_site varchar(50) =default ,@cc_email varchar(100) =default ,@cc_msnqq varchar(50) =default ,@cc_monthday varchar(4) =default ,@cc_identno varchar(20) =default ,@cc_aaaaa varchar(20) =default ,@cc_branch nvarchar(50) =default ,@cc_depart nvarchar(50) =default ,@cc_cuname nvarchar(50) =default ,@cc_caption nvarchar(50) =default ,@cc_type nvarchar(50) =default ,@cc_code nvarchar(50) =default ,@cc_dqqsa nvarchar(100) =default ,@cc_opod nvarchar(100) =default ,@cc_posid nvarchar(100) =default ,@cc_p1osid nvarchar(100) =default ,@cc_status nvarchar(50) =default ,@cc_other nvarchar(200) =default ,@cc_identtype nvarchar(20) =default ,@cc_dsa nvarchar(100) =default ,@cc_cds nvarchar(50) =default ,@cc_dqqqsa nvarchar(100) =default ,@cc_county nvarchar(20) =default ,@cc_native nvarchar(30) =default ,@cc_college nvarchar(50) =default ,@cc_taboos nvarchar(200) =default ,@cc_addr nvarchar(100) =default ,@cc_source nvarchar(50) =default ,@cc_createdepart nvarchar(50) =default ,@cc_creator nvarchar(50) =default ,@cc_name nvarchar(50) =default ,@cc_company nvarchar(50) =default ,@cc_province nvarchar(20) =default ,@cc_municipal nvarchar(20) =default  ) 
as  
begin  
set nocount on  
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
declare @nonedate datetime 
set @nonedate = CONVERT(datetime,'1910-1-1')
 declare @operation varchar(50)
declare @errorinfo nvarchar(4000) 
 set @operation = 'continue' 
set @errorinfo = '' 

-- 处理编码
 declare @bmcode varchar(200) 
 declare @newno nvarchar(50) 
 declare @ctid int 
 select top 1 @ctid=cc_ctid,@bmcode = ct_bmcode from mps_customer,mps_csttype where cc_id=@ccid and cc_ctid=ct_id and (cc_code='' or cc_code like '%临%')
 set @ctid = isnull(@ctid,0) 
 if (@ctid>0) 
 begin
exec mps_bm_getorset @cmpid,'cst',@ctid,@ccid,@useruid,@bmcode,0,@newno output,1
set @cc_code = @newno 
end 

 --- 以下是预处理事件中的临时表
 
exec drop_temp_table '#old' 
select * into #old from mps_customer where cc_id=@ccid 
exec drop_temp_table '#account' 
create table #account(acctype varchar(30),acccategory varchar(30),accdate varchar(30),fiidreal int,fiid int,objidreal bigint,objid bigint,origin int,value int,used int,suspended int,ready int,changed int,available int,actual int) 
exec drop_temp_table '#new' 
select * , case when ((@sourcefield is null) or (@sourcefield = '_none_')) then '' else @sourcefield end sourcefield into #new from #old 
update #new set 
cc_branch=case when @cc_branch is null or @cc_branch = '_none_'  then cc_branch else @cc_branch end,cc_dpid=case when @cc_dpid is null or @cc_dpid = -999999999  then cc_dpid else @cc_dpid end,cc_depart=case when @cc_depart is null or @cc_depart = '_none_'  then cc_depart else @cc_depart end,cc_cuid=case when @cc_cuid is null or @cc_cuid = -999999999  then cc_cuid else @cc_cuid end,cc_cuname=case when @cc_cuname is null or @cc_cuname = '_none_'  then cc_cuname else @cc_cuname end,cc_caption=case when @cc_caption is null or @cc_caption = '_none_'  then cc_caption else @cc_caption end,cc_type=case when @cc_type is null or @cc_type = '_none_'  then cc_type else @cc_type end,cc_code=case when @cc_code is null or @cc_code = '_none_'  then cc_code else @cc_code end,cc_createdpid=case when @cc_createdpid is null or @cc_createdpid = -999999999  then cc_createdpid else @cc_createdpid end,cc_createdepart=case when @cc_createdepart is null or @cc_createdepart = '_none_'  then cc_createdepart else @cc_createdepart end,cc_createcuid=case when @cc_createcuid is null or @cc_createcuid = -999999999  then cc_createcuid else @cc_createcuid end,cc_creator=case when @cc_creator is null or @cc_creator = '_none_'  then cc_creator else @cc_creator end,cc_name=case when @cc_name is null or @cc_name = '_none_'  then cc_name else @cc_name end,cc_company=case when @cc_company is null or @cc_company = '_none_'  then cc_company else @cc_company end,cc_gender=case when @cc_gender is null or @cc_gender = -999999999  then cc_gender else @cc_gender end,cc_mobile=case when @cc_mobile is null or @cc_mobile = '_none_'  then cc_mobile else @cc_mobile end,cc_contact=case when @cc_contact is null or @cc_contact = '_none_'  then cc_contact else @cc_contact end,cc_icon=case when @cc_icon is null or @cc_icon = '_none_'  then cc_icon else @cc_icon end,cc_fccid=case when @cc_fccid is null or @cc_fccid = -999999999  then cc_fccid else @cc_fccid end,cc_province=case when @cc_province is null or @cc_province = '_none_'  then cc_province else @cc_province end,cc_municipal=case when @cc_municipal is null or @cc_municipal = '_none_'  then cc_municipal else @cc_municipal end,cc_county=case when @cc_county is null or @cc_county = '_none_'  then cc_county else @cc_county end,cc_title=case when @cc_title is null or @cc_title = '_none_'  then cc_title else @cc_title end,cc_prof=case when @cc_prof is null or @cc_prof = '_none_'  then cc_prof else @cc_prof end,cc_native=case when @cc_native is null or @cc_native = '_none_'  then cc_native else @cc_native end,cc_college=case when @cc_college is null or @cc_college = '_none_'  then cc_college else @cc_college end,cc_taboos=case when @cc_taboos is null or @cc_taboos = '_none_'  then cc_taboos else @cc_taboos end,cc_addr=case when @cc_addr is null or @cc_addr = '_none_'  then cc_addr else @cc_addr end,cc_post=case when @cc_post is null or @cc_post = '_none_'  then cc_post else @cc_post end,cc_source=case when @cc_source is null or @cc_source = '_none_'  then cc_source else @cc_source end,cc_site=case when @cc_site is null or @cc_site = '_none_'  then cc_site else @cc_site end,cc_email=case when @cc_email is null or @cc_email = '_none_'  then cc_email else @cc_email end,cc_msnqq=case when @cc_msnqq is null or @cc_msnqq = '_none_'  then cc_msnqq else @cc_msnqq end,cc_status=case when @cc_status is null or @cc_status = '_none_'  then cc_status else @cc_status end,cc_health=case when @cc_health is null or @cc_health = -999999999  then cc_health else @cc_health end,cc_score=case when @cc_score is null or @cc_score = -999999999  then cc_score else @cc_score end,cc_total=case when @cc_total is null or @cc_total = -999999999  then cc_total else @cc_total end,cc_value=case when @cc_value is null or @cc_value = -999999999  then cc_value else @cc_value end,cc_prev=case when @cc_prev is null or @cc_prev = -999999999  then cc_prev else @cc_prev end,cc_rear=case when @cc_rear is null or @cc_rear = -999999999  then cc_rear else @cc_rear end,cc_allowlogin=case when @cc_allowlogin is null or @cc_allowlogin = -999999999  then cc_allowlogin else @cc_allowlogin end,cc_other=case when @cc_other is null or @cc_other = '_none_'  then cc_other else @cc_other end,cc_birth=case when @cc_birth is null or @cc_birth = @nonedate then cc_birth else @cc_birth end,cc_monthday=case when @cc_monthday is null or @cc_monthday = '_none_'  then cc_monthday else @cc_monthday end,cc_creditquantum=case when @cc_creditquantum is null or @cc_creditquantum = -999999999  then cc_creditquantum else @cc_creditquantum end,cc_accountperiod=case when @cc_accountperiod is null or @cc_accountperiod = -999999999  then cc_accountperiod else @cc_accountperiod end,cc_use=case when @cc_use is null or @cc_use = -999999999  then cc_use else @cc_use end,cc_identtype=case when @cc_identtype is null or @cc_identtype = '_none_'  then cc_identtype else @cc_identtype end,cc_identno=case when @cc_identno is null or @cc_identno = '_none_'  then cc_identno else @cc_identno end,cc_dsa=case when @cc_dsa is null or @cc_dsa = '_none_'  then cc_dsa else @cc_dsa end,cc_cds=case when @cc_cds is null or @cc_cds = '_none_'  then cc_cds else @cc_cds end,cc_security=case when @cc_security is null or @cc_security = -999999999  then cc_security else @cc_security end,cc_aaaaa=case when @cc_aaaaa is null or @cc_aaaaa = '_none_'  then cc_aaaaa else @cc_aaaaa end,cc_dqqqsa=case when @cc_dqqqsa is null or @cc_dqqqsa = '_none_'  then cc_dqqqsa else @cc_dqqqsa end,cc_dqqsa=case when @cc_dqqsa is null or @cc_dqqsa = '_none_'  then cc_dqqsa else @cc_dqqsa end,cc_opod=case when @cc_opod is null or @cc_opod = '_none_'  then cc_opod else @cc_opod end,cc_posid=case when @cc_posid is null or @cc_posid = '_none_'  then cc_posid else @cc_posid end,cc_p1osid=case when @cc_p1osid is null or @cc_p1osid = '_none_'  then cc_p1osid else @cc_p1osid end
exec mps_customer_modify_before @cmpid,@branchid,@userdpid,@useruid,@userotid,@ccid,@operation output,@errorinfo output   
 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,
old.cc_updated=getdate() 
from mps_customer old,#new new where old.cc_id=new.cc_id 
exec mps_customer_modify_after @cmpid,@branchid,@userdpid,@useruid,@userotid,@ccid 

 select 'ok' operation, '' errorinfo 
end  else 
begin
select @operation operation, @errorinfo errorinfo  
end

exec drop_temp_table '#new' 
exec drop_temp_table '#account' 
exec drop_temp_table '#old' 

 
set nocount off 
end