IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[proj_48_loaddata]') AND type = 'P')
DROP PROCEDURE [dbo].[proj_48_loaddata]
GO
CREATE proc [dbo].[proj_48_loaddata](
@ordid bigint,
@str nvarchar(max),
@ord2id bigint
)
as
begin
set nocount on
    declare @strone nvarchar(20),
            @index int,
            @errstr nvarchar(max),
            @ordid2 bigint,
            @ristr nvarchar(max),
@name nvarchar(20),
@restr nvarchar(max)
declare @QD table(usename nvarchar(40),sfz nvarchar(30))
    set @errstr = ''
    set @ristr = ''
set @restr = ''
    while @str > ''
    begin
        set @index = charindex(',',@str)
        if @index > 0
        begin
            set @strone = substring(@str,1,@index-1)

            select @ordid2 = ord2_id ,@name = ord2_xm from order_48_105 where @strone =  ord2_sfz and @ordid = ord2_ordid 

            if exists (select 1 from order_48_105 where ord2_id = @ordid2 and ord2_ordid = @ordid 
            and ord2_sfbm = '是')
            begin
/************判断重复***************************/
if charindex(@strone,@ristr) > 0
begin
set @restr = @restr+@strone+','
end
else
begin
set @ristr = @ristr+@strone+','
end
            end
            else
            if exists(select 1 from order_48_105 
            where ord2_ordid = @ordid and ord2_id = @ordid2 and (ord2_sfbm ='否' or ord2_sfbm =''))
            begin
                set @errstr = @errstr+@strone+char(10)
insert into @QD(usename,sfz) values(@name,@strone)
            end
                set @str = substring(@str,@index+1,len(@str))
        end
        else
        begin
            set @str = ''
        end
    end

    if @errstr >  ''
    begin

select 'errorinfo' result,* from @QD 
    end
    else
    begin
while @ristr > ''
    begin
        set @index = charindex(',',@ristr)
        if @index > 0
        begin
            set @strone = substring(@ristr,1,@index-1)


            exec proj_qsy_TrainSignin @ordid,@strone,@ord2id
            set @ristr = substring(@ristr,@index+1,len(@ristr))
        end
        else
        begin
            set @ristr = ''
        end
select 'ok' result3
    end 
    end
    set nocount off
    
end