IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[userfunc_744_afterdelreload]') AND type = 'P')
DROP PROCEDURE [dbo].[userfunc_744_afterdelreload]
GO
CREATE PROCEDURE userfunc_744_afterdelreload(@cmpid int,   @branchid int,  @userdpid int,  @useruid int,   @userotid int,  @usersecurity int,@ctgid int,@ctgid2 int,@objid bigint,@ordid1 int,@type varchar(100))
as
begin


set nocount on 
declare @objtype varchar(20)='biz' 
declare @ordid bigint 
set @ordid=@objid 
declare @bizid int 
set @bizid = @ctgid 
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 @temp table  (dp nvarchar(100),info nvarchar(100))
    declare @t1 table (str nvarchar(max))
    if(@type ='维修机')
    begin
        
        insert into @temp
        select ord2_jjmd,ord2_pp+'('+cast(count(*) as nvarchar(50))+'个)' as co 
        from order_266_2 where ord2_ordid =@ordid1 group by ord2_jjmd,ord2_pp
        insert into @t1
        select '【'+a.dp+'】:'+(stuff((select ','+info from @temp where dp = a.dp for xml path('')),1,1,'')) from @temp a group by dp
        update order_266 set ord_gl = (select top 1 stuff((select ';'+str from @t1 for xml path('')),1,1,'') as str from @t1) where ord_id = @ordid1
        select ord_gl as gl from order_266 where ord_id = @ordid1
        select 'OK' result1     
    end
    else if(@type = '旧件')
    begin
        
        insert into @temp
        select ord2_sjmd,ord2_pp+'('+cast(count(*) as nvarchar(50))+'个)' as co 
        from order_266_3 where ord2_ordid =@ordid1 group by ord2_sjmd,ord2_pp
        insert into @t1
        select '【'+a.dp+'】:'+(stuff((select ','+info from @temp where dp = a.dp for xml path('')),1,1,'')) from @temp a group by dp
        update order_266 set ord_gl = (select top 1 stuff((select ';'+str from @t1 for xml path('')),1,1,'') as str from @t1) where ord_id = @ordid1
        select ord_gl as gl from order_266 where ord_id = @ordid1
        select 'OK' result1
    end



end