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

-- 生成时间:2018-05-28 18:55:10 by ebs-core  
CREATE  procedure order_48_modify_105(
@ord2id bigint, 
@cmpid int, 
@branchid bigint, 
@userdpid bigint, 
@userotid bigint, 
@useruid int, 
@jbid bigint, 
@ordid bigint, 
@ord2tag int,@sourcefield varchar(50)=default, 
@ord2_fbizid int =default ,@ord2_ford2tag int =default ,@ord2_order int =default ,@ord2_rbizid int =default ,@ord2_rord2tag int =default ,@ord2_sqdcs int =default ,@ord2_yqdcs int =default ,@ord2_llfs decimal(18,2) =default ,@ord2_zhpfs decimal(18,2) =default ,@ord2_scfs decimal(18,2) =default ,@ord2_fatherord2id bigint =default ,@ord2_ford2id bigint =default ,@ord2_fordid bigint =default ,@ord2_rord2id bigint =default ,@ord2_rordid bigint =default ,@ord2_pxcuid bigint =default ,@ord2_pxid bigint =default ,@ord2_code varchar(50) =default ,@ord2_ftype varchar(10) =default ,@ord2_key varchar(30) =default ,@ord2_rtype varchar(10) =default ,@ord2_tags varchar(100) =default ,@ord2_bmqk nvarchar(100) =default ,@ord2_caption nvarchar(100) =default ,@ord2_mdlx nvarchar(100) =default ,@ord2_mdmc nvarchar(100) =default ,@ord2_pxjg nvarchar(100) =default ,@ord2_qdxq nvarchar(100) =default ,@ord2_ygbh nvarchar(100) =default ,@ord2_bz nvarchar(100) =default ,@ord2_lxdh nvarchar(100) =default ,@ord2_zj nvarchar(100) =default ,@ord2_ksfs nvarchar(100) =default ,@ord2_sfbm nvarchar(100) =default ,@ord2_sfz nvarchar(100) =default ,@ord2_sfzs nvarchar(100) =default ,@ord2_sspq nvarchar(100) =default ,@ord2_status nvarchar(30) =default ,@ord2_xm nvarchar(100) =default  ) 
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 = '' 
 --- 以下是预处理事件中的临时表
 declare @needreturn int 
 set @needreturn = 1
 if (@ord2id=0)  -- 如果=0
 begin
 set @ord2id=-1
 set @needreturn = 0
 exec order_48_105_newdetail @cmpid , @branchid , @userdpid, @useruid , @userotid, @jbid , @ordid ,@ord2tag ,@ord2id output , '' 
 if (@ord2id<=0) set @ord2id=0 
 end 
 
exec drop_temp_table '#old' 
select * into #old from order_48_105 where ord2_id=@ord2id 
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 * ,null recid , case when ((@sourcefield is null) or (@sourcefield = '_none_')) then '' else @sourcefield end sourcefield 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_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_sqdcs=case when @ord2_sqdcs is null or @ord2_sqdcs = -999999999  then ord2_sqdcs else @ord2_sqdcs end,ord2_yqdcs=case when @ord2_yqdcs is null or @ord2_yqdcs = -999999999  then ord2_yqdcs else @ord2_yqdcs end,ord2_llfs=case when @ord2_llfs is null or @ord2_llfs = -999999999  then ord2_llfs else @ord2_llfs end,ord2_zhpfs=case when @ord2_zhpfs is null or @ord2_zhpfs = -999999999  then ord2_zhpfs else @ord2_zhpfs end,ord2_scfs=case when @ord2_scfs is null or @ord2_scfs = -999999999  then ord2_scfs else @ord2_scfs 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_pxcuid=case when @ord2_pxcuid is null or @ord2_pxcuid = -999999999  then ord2_pxcuid else @ord2_pxcuid end,ord2_pxid=case when @ord2_pxid is null or @ord2_pxid = -999999999  then ord2_pxid else @ord2_pxid 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_bmqk=case when @ord2_bmqk is null or @ord2_bmqk = '_none_'  then ord2_bmqk else @ord2_bmqk end,ord2_caption=case when @ord2_caption is null or @ord2_caption = '_none_'  then ord2_caption else @ord2_caption end,ord2_mdlx=case when @ord2_mdlx is null or @ord2_mdlx = '_none_'  then ord2_mdlx else @ord2_mdlx end,ord2_mdmc=case when @ord2_mdmc is null or @ord2_mdmc = '_none_'  then ord2_mdmc else @ord2_mdmc end,ord2_pxjg=case when @ord2_pxjg is null or @ord2_pxjg = '_none_'  then ord2_pxjg else @ord2_pxjg end,ord2_qdxq=case when @ord2_qdxq is null or @ord2_qdxq = '_none_'  then ord2_qdxq else @ord2_qdxq end,ord2_ygbh=case when @ord2_ygbh is null or @ord2_ygbh = '_none_'  then ord2_ygbh else @ord2_ygbh end,ord2_bz=case when @ord2_bz is null or @ord2_bz = '_none_'  then ord2_bz else @ord2_bz end,ord2_lxdh=case when @ord2_lxdh is null or @ord2_lxdh = '_none_'  then ord2_lxdh else @ord2_lxdh end,ord2_zj=case when @ord2_zj is null or @ord2_zj = '_none_'  then ord2_zj else @ord2_zj end,ord2_ksfs=case when @ord2_ksfs is null or @ord2_ksfs = '_none_'  then ord2_ksfs else @ord2_ksfs end,ord2_sfbm=case when @ord2_sfbm is null or @ord2_sfbm = '_none_'  then ord2_sfbm else @ord2_sfbm end,ord2_sfz=case when @ord2_sfz is null or @ord2_sfz = '_none_'  then ord2_sfz else @ord2_sfz end,ord2_sfzs=case when @ord2_sfzs is null or @ord2_sfzs = '_none_'  then ord2_sfzs else @ord2_sfzs end,ord2_sspq=case when @ord2_sspq is null or @ord2_sspq = '_none_'  then ord2_sspq else @ord2_sspq end,ord2_status=case when @ord2_status is null or @ord2_status = '_none_'  then ord2_status else @ord2_status end,ord2_xm=case when @ord2_xm is null or @ord2_xm = '_none_'  then ord2_xm else @ord2_xm end
update #new set recid=ord2_id 

 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_sqdcs=case when new.ord2_sqdcs is null or new.ord2_sqdcs = -999999999  then old.ord2_sqdcs else new.ord2_sqdcs end,ord2_yqdcs=case when new.ord2_yqdcs is null or new.ord2_yqdcs = -999999999  then old.ord2_yqdcs else new.ord2_yqdcs end,ord2_llfs=case when new.ord2_llfs is null or new.ord2_llfs = -999999999  then old.ord2_llfs else new.ord2_llfs end,ord2_zhpfs=case when new.ord2_zhpfs is null or new.ord2_zhpfs = -999999999  then old.ord2_zhpfs else new.ord2_zhpfs end,ord2_scfs=case when new.ord2_scfs is null or new.ord2_scfs = -999999999  then old.ord2_scfs else new.ord2_scfs 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_pxcuid=case when new.ord2_pxcuid is null or new.ord2_pxcuid = -999999999  then old.ord2_pxcuid else new.ord2_pxcuid end,ord2_pxid=case when new.ord2_pxid is null or new.ord2_pxid = -999999999  then old.ord2_pxid else new.ord2_pxid 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_bmqk=case when new.ord2_bmqk is null or new.ord2_bmqk = '_none_'  then old.ord2_bmqk else new.ord2_bmqk 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_mdlx=case when new.ord2_mdlx is null or new.ord2_mdlx = '_none_'  then old.ord2_mdlx else new.ord2_mdlx end,ord2_mdmc=case when new.ord2_mdmc is null or new.ord2_mdmc = '_none_'  then old.ord2_mdmc else new.ord2_mdmc end,ord2_pxjg=case when new.ord2_pxjg is null or new.ord2_pxjg = '_none_'  then old.ord2_pxjg else new.ord2_pxjg end,ord2_qdxq=case when new.ord2_qdxq is null or new.ord2_qdxq = '_none_'  then old.ord2_qdxq else new.ord2_qdxq end,ord2_ygbh=case when new.ord2_ygbh is null or new.ord2_ygbh = '_none_'  then old.ord2_ygbh else new.ord2_ygbh 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_lxdh=case when new.ord2_lxdh is null or new.ord2_lxdh = '_none_'  then old.ord2_lxdh else new.ord2_lxdh end,ord2_zj=case when new.ord2_zj is null or new.ord2_zj = '_none_'  then old.ord2_zj else new.ord2_zj end,ord2_ksfs=case when new.ord2_ksfs is null or new.ord2_ksfs = '_none_'  then old.ord2_ksfs else new.ord2_ksfs end,ord2_sfbm=case when new.ord2_sfbm is null or new.ord2_sfbm = '_none_'  then old.ord2_sfbm else new.ord2_sfbm end,ord2_sfz=case when new.ord2_sfz is null or new.ord2_sfz = '_none_'  then old.ord2_sfz else new.ord2_sfz end,ord2_sfzs=case when new.ord2_sfzs is null or new.ord2_sfzs = '_none_'  then old.ord2_sfzs else new.ord2_sfzs end,ord2_sspq=case when new.ord2_sspq is null or new.ord2_sspq = '_none_'  then old.ord2_sspq else new.ord2_sspq 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_xm=case when new.ord2_xm is null or new.ord2_xm = '_none_'  then old.ord2_xm else new.ord2_xm end,
ord2_updated=getdate() 
from order_48_105 old,#new new where old.ord2_id=new.ord2_id and (new.recid is not null) 
exec order_48_modify_105_after @cmpid ,@branchid ,@userdpid,@useruid,@userotid,@jbid,@ordid,@ord2tag,@ord2id 

 if (@needreturn=1) select 'ok' operation, '' errorinfo 
 else select * from order_48_105 where ord2_id=@ord2id
end  else 
begin
if (@needreturn=1) select @operation operation, @errorinfo errorinfo  
else select 0 none , 1 none1 where 1=0 
end

exec drop_temp_table '#new' 
exec drop_temp_table '#account' 
exec drop_temp_table '#old' 
set nocount off 
end