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

-- 生成时间:2018-05-04 09:51:47 by ebs-core  
CREATE  procedure order_32_modify_2(
@ord2id bigint, 
@cmpid int, 
@branchid bigint, 
@userdpid bigint, 
@userotid bigint, 
@useruid int, 
@jbid bigint, 
@ordid bigint, 
@ord2tag int, 
@ord2_fbizid int,@ord2_ford2tag int,@ord2_order int,@ord2_rbizid int,@ord2_rord2tag int,@ord2_enddate datetime,@ord2_rxrq datetime,@ord2_jyrq datetime,@ord2_jsrq datetime,@ord2_ksrq datetime,@ord2_fatherord2id bigint,@ord2_ford2id bigint,@ord2_fordid bigint,@ord2_rord2id bigint,@ord2_rordid bigint,@ord2_fdpid bigint,@ord2_fcuid bigint,@ord2_code varchar(50),@ord2_ftype varchar(10),@ord2_key varchar(30),@ord2_rtype varchar(10),@ord2_tags varchar(100),@ord2_caption nvarchar(100),@ord2_note nvarchar(100),@ord2_schoolname nvarchar(100),@ord2_status nvarchar(30),@ord2_rzqk nvarchar(100),@ord2_byrs nvarchar(100),@ord2_jjx nvarchar(100),@ord2_jjzt nvarchar(100),@ord2_byyx nvarchar(100),@ord2_bz nvarchar(100),@ord2_sptz nvarchar(100),@ord2_jjbm nvarchar(100),@ord2_jjnr nvarchar(100),@ord2_jjr nvarchar(100) ) 
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_32_2_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_32_2 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 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_enddate=case when @ord2_enddate is null or @ord2_enddate = @nonedate then ord2_enddate else @ord2_enddate end,ord2_rxrq=case when @ord2_rxrq is null or @ord2_rxrq = @nonedate then ord2_rxrq else @ord2_rxrq end,ord2_jyrq=case when @ord2_jyrq is null or @ord2_jyrq = @nonedate then ord2_jyrq else @ord2_jyrq end,ord2_jsrq=case when @ord2_jsrq is null or @ord2_jsrq = @nonedate then ord2_jsrq else @ord2_jsrq end,ord2_ksrq=case when @ord2_ksrq is null or @ord2_ksrq = @nonedate then ord2_ksrq else @ord2_ksrq 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_fdpid=case when @ord2_fdpid is null or @ord2_fdpid = -999999999  then ord2_fdpid else @ord2_fdpid end,ord2_fcuid=case when @ord2_fcuid is null or @ord2_fcuid = -999999999  then ord2_fcuid else @ord2_fcuid 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_caption=case when @ord2_caption is null or @ord2_caption = '_none_'  then ord2_caption else @ord2_caption end,ord2_note=case when @ord2_note is null or @ord2_note = '_none_'  then ord2_note else @ord2_note end,ord2_schoolname=case when @ord2_schoolname is null or @ord2_schoolname = '_none_'  then ord2_schoolname else @ord2_schoolname end,ord2_status=case when @ord2_status is null or @ord2_status = '_none_'  then ord2_status else @ord2_status end,ord2_rzqk=case when @ord2_rzqk is null or @ord2_rzqk = '_none_'  then ord2_rzqk else @ord2_rzqk end,ord2_byrs=case when @ord2_byrs is null or @ord2_byrs = '_none_'  then ord2_byrs else @ord2_byrs end,ord2_jjx=case when @ord2_jjx is null or @ord2_jjx = '_none_'  then ord2_jjx else @ord2_jjx end,ord2_jjzt=case when @ord2_jjzt is null or @ord2_jjzt = '_none_'  then ord2_jjzt else @ord2_jjzt end,ord2_byyx=case when @ord2_byyx is null or @ord2_byyx = '_none_'  then ord2_byyx else @ord2_byyx end,ord2_bz=case when @ord2_bz is null or @ord2_bz = '_none_'  then ord2_bz else @ord2_bz end,ord2_sptz=case when @ord2_sptz is null or @ord2_sptz = '_none_'  then ord2_sptz else @ord2_sptz end,ord2_jjbm=case when @ord2_jjbm is null or @ord2_jjbm = '_none_'  then ord2_jjbm else @ord2_jjbm end,ord2_jjnr=case when @ord2_jjnr is null or @ord2_jjnr = '_none_'  then ord2_jjnr else @ord2_jjnr end,ord2_jjr=case when @ord2_jjr is null or @ord2_jjr = '_none_'  then ord2_jjr else @ord2_jjr 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_enddate=case when new.ord2_enddate is null or new.ord2_enddate = @nonedate then old.ord2_enddate else new.ord2_enddate end,ord2_rxrq=case when new.ord2_rxrq is null or new.ord2_rxrq = @nonedate then old.ord2_rxrq else new.ord2_rxrq end,ord2_jyrq=case when new.ord2_jyrq is null or new.ord2_jyrq = @nonedate then old.ord2_jyrq else new.ord2_jyrq end,ord2_jsrq=case when new.ord2_jsrq is null or new.ord2_jsrq = @nonedate then old.ord2_jsrq else new.ord2_jsrq end,ord2_ksrq=case when new.ord2_ksrq is null or new.ord2_ksrq = @nonedate then old.ord2_ksrq else new.ord2_ksrq 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_fdpid=case when new.ord2_fdpid is null or new.ord2_fdpid = -999999999  then old.ord2_fdpid else new.ord2_fdpid end,ord2_fcuid=case when new.ord2_fcuid is null or new.ord2_fcuid = -999999999  then old.ord2_fcuid else new.ord2_fcuid 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_caption=case when new.ord2_caption is null or new.ord2_caption = '_none_'  then old.ord2_caption else new.ord2_caption end,ord2_note=case when new.ord2_note is null or new.ord2_note = '_none_'  then old.ord2_note else new.ord2_note end,ord2_schoolname=case when new.ord2_schoolname is null or new.ord2_schoolname = '_none_'  then old.ord2_schoolname else new.ord2_schoolname 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_rzqk=case when new.ord2_rzqk is null or new.ord2_rzqk = '_none_'  then old.ord2_rzqk else new.ord2_rzqk end,ord2_byrs=case when new.ord2_byrs is null or new.ord2_byrs = '_none_'  then old.ord2_byrs else new.ord2_byrs end,ord2_jjx=case when new.ord2_jjx is null or new.ord2_jjx = '_none_'  then old.ord2_jjx else new.ord2_jjx end,ord2_jjzt=case when new.ord2_jjzt is null or new.ord2_jjzt = '_none_'  then old.ord2_jjzt else new.ord2_jjzt end,ord2_byyx=case when new.ord2_byyx is null or new.ord2_byyx = '_none_'  then old.ord2_byyx else new.ord2_byyx 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_sptz=case when new.ord2_sptz is null or new.ord2_sptz = '_none_'  then old.ord2_sptz else new.ord2_sptz end,ord2_jjbm=case when new.ord2_jjbm is null or new.ord2_jjbm = '_none_'  then old.ord2_jjbm else new.ord2_jjbm end,ord2_jjnr=case when new.ord2_jjnr is null or new.ord2_jjnr = '_none_'  then old.ord2_jjnr else new.ord2_jjnr end,ord2_jjr=case when new.ord2_jjr is null or new.ord2_jjr = '_none_'  then old.ord2_jjr else new.ord2_jjr end,
ord2_updated=getdate() 
from order_32_2 old,#new new where old.ord2_id=new.ord2_id and (new.recid is not null) 
exec order_32_modify_2_after @cmpid ,@branchid ,@userdpid,@useruid,@userotid,@jbid,@ordid,@ord2tag,@ord2id 

 if (@needreturn=1) select 'ok' operation, '' errorinfo 
 else select * from order_32_2 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