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

-- 生成时间:2018-06-26 17:51:29 by ebs-core  
CREATE  procedure order_20_2_newdetail(
@cmpid int, 
@branchid int, 
@userdpid int, 
@useruid int, 
@userotid int, 
@jbid bigint, 
@ordid bigint, 
@ord2tag int, 
@ord2id bigint output, 
@ord2group nvarchar(50)
) 
as  
begin  
set nocount on 
declare @neword2id bigint
insert into order_20_2(ord2_ordid, ord2_tag, ord2_group, ord2_updated) values(@ordid, @ord2tag, @ord2group,GETDATE()) 
declare @nonedate datetime 
set @nonedate = CONVERT(datetime,'1910-1-1')
--set @neword2id = @@Identity 
select  top 1 @neword2id = ord2_id from order_20_2 where ord2_ordid=@ordid  order by ord2_id desc 
set @neword2id = isnull(@neword2id,0) 
declare @ord2group2 nvarchar(50) 
set @ord2group2 = '' 
declare @sys_recid bigint 
set @sys_recid = 0 
declare @errorinfo nvarchar(4000) 
declare @operation varchar(50) 
set @operation = 'continue' 
set @errorinfo = '' 

declare @noreturn int 
set @noreturn = 1 
if (@ord2id=-1) 
begin
set @ord2id = 0 
set @noreturn = 0 
end
-- 考虑到批量添加或导入功能，事件处理程序不在此完成 
exec drop_temp_table '#new' 
select * ,null recid ,'' sourcefield into #new from order_20_2 where ord2_id=@neword2id 

 alter table #new add default 0 for ord2_fbizid   alter table #new add default 0 for ord2_ford2tag   alter table #new add default 0 for ord2_jhbz   alter table #new add default 0 for ord2_order   alter table #new add default 0 for ord2_rbizid   alter table #new add default 0 for ord2_rord2tag   alter table #new add default 0 for ord2_tag   alter table #new add default 0 for ord2_zbrs   alter table #new add default 0 for ord2_bgid   alter table #new add default '1900-1-1' for ord2_date   alter table #new add default '1900-1-1' for ord2_updated   alter table #new add default 0 for ord2_fatherord2id   alter table #new add default 0 for ord2_ford2id   alter table #new add default 0 for ord2_fordid   alter table #new add default 0 for ord2_ordid   alter table #new add default 0 for ord2_rord2id   alter table #new add default 0 for ord2_rordid   alter table #new add default '' for ord2_code   alter table #new add default '' for ord2_ftype   alter table #new add default '' for ord2_key   alter table #new add default '' for ord2_rtype   alter table #new add default '' for ord2_tags   alter table #new add default '' for ord2_bmmc   alter table #new add default '' for ord2_bz   alter table #new add default '' for ord2_caption   alter table #new add default '' for ord2_group   alter table #new add default '' for ord2_gw   alter table #new add default '' for ord2_status   alter table #new add default '' for ord2_bznd 
update #new set recid=ord2_id 

if (@operation <> 'continue') 
begin 
-- 将新增的那条记录删除 
set @nonedate = @nonedate   -- here useless 

delete order_20_2 from #new a where order_20_2.ord2_id = a.ord2_id 

if (@errorinfo = '') set @errorinfo = 'error' 
set @neword2id = 0 
if (@noreturn>0) select 0 none where 0 = 1 
if (@noreturn=0) set @ord2id=@neword2id 
end else 
begin 
  set @nonedate=@nonedate  -- here useless 
exec order_20_2_newdetail_after  @cmpid,@branchid,@userdpid,@useruid,@userotid,@jbid,@ordid ,@ord2tag,@ord2group ,@neword2id 
if (@noreturn>0)  select * from order_20_2 where ord2_id = @neword2id 
else set @ord2id=@neword2id 
end
exec drop_temp_table '#new' 

set nocount off
end