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

create procedure order_45_newbizbysrc (
    @cmpid int , 
    @bcid int ,
    @branch nvarchar(50),
    @dpid int ,
    @depart nvarchar(50),
    @createcuid int ,
    @cuname nvarchar(50),
    @jbid bigint ,
    @bizstyle int,
    @biztitle nvarchar(100),  
    @bizcode nvarchar(100),
    @stype varchar(10) ,
    @sbizid int ,
    @sordid bigint ,
    @sord2tag int ,
    @sord2id bigint, 
    @newordids varchar(2000) output 
   ) 
  as 
  begin 
set @jbid = isnull(@jbid,0) 
if (@jbid=-999999999) set @jbid=0
declare @ordno varchar(50)
  declare @maxordid bigint 
  declare @ord table(ordid bigint , ordno varchar(50)) 
  declare @newcount int 
  set @newcount = 0 
  declare @newordid bigint
  
select @maxordid = max(ord_id) from order_45  
set @maxordid = isnull(@maxordid , 0 ) 

insert into order_45(ord_cmpid,ord_style,ord_bcid,ord_branch,ord_bizid,ord_type,ord_date,ord_updated, 
ord_createdpid,ord_createcuid,ord_createdepart,ord_creator,ord_finished,ord_fjbid)  
select @cmpid,@bizstyle,@bcid,@branch,45,@biztitle,getdate(),getdate(), @dpid,@createcuid,@depart,@cuname ,1 , @jbid  
set @newordid=@@Identity  
set @newordid=isnull(@newordid,0) 
if (@newordid>0) exec mps_bm_getorset @cmpid,'biz',45,@newordid,@createcuid,@bizcode,2,@ordno output,1 
if (@newordid>0) 
begin
set @newcount = @newcount + 1
insert into @ord(ordid,ordno) values(@newordid,@ordno)  
update order_45 set ord_no=@ordno where ord_id=@newordid 
end
set @newordids=null 
select @newordids=ISNULL(@newordids+',','')+convert(varchar(16),ordid) from @ord 
set @newordids = isnull(@newordids,'')  
end