IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[proj_qsy_TrainSignin]') AND type = 'P')
DROP PROCEDURE [dbo].[proj_qsy_TrainSignin]
GO
CREATE proc [dbo].[proj_qsy_TrainSignin](
    @ordid int,
    @str nvarchar(20),
    @ord2id int
)
as
begin

set nocount on
    declare @ord2id2 int,
@minid int,
@sfbm nvarchar(20)
    
    select @ord2id2=ord2_id from order_48_105 where ord2_sfz = @str and ord2_ordid = @ordid 
    select @minid=MIN(ord2_id) from order_48_3 where ord2_ordid = @ordid
    select @sfbm = ord2_sfbm from order_48_105 where ord2_sfz = @str and @ord2id = @minid and ord2_ordid = @ordid
    if exists(select 1 from order_48_105 where ord2_ordid = @ordid and ord2_id = @ord2id2 and ord2_sfbm ='是')
        begin         
update order_48_105 set ord2_sqdcs = ord2_sqdcs + 1 where ord2_ordid = @ordid and ord2_id = @ord2id2
select  'ok' result1,* from order_48_105 where ord2_ordid = @ordid and ord2_id = @ord2id2

end
     else 
     if exists(select 1 from order_48_105 
     where ord2_ordid = @ordid and ord2_id = @ord2id2 and (ord2_sfbm ='否' or ord2_sfbm =''))
        begin
            select  'error' result1,* from order_48_105 where ord2_ordid = @ordid and ord2_id = @ord2id2
        end
     else
     if not exists(select 1 from order_48_105 
     where ord2_ordid = @ordid and ord2_id = @ord2id2 )
begin
select 'notfound' result1
end

     if @ord2id =@minid and @sfbm = '是' 
begin
select 'print1'  dayin,@ord2id a,@minid b,@ordid c
end
else 
begin
select 'notprint1'  dayin,@ord2id a,@minid b,@ordid c
end
set nocount off

end