Delimiter //
/**
* détermine l'id du membre a accréditer en fonction du login founi
**/

Drop Procedure if exists LOADER_ATTACHEDMEMBERS_NORMALIZE_MAP_MEMBERS_WITH_LOGIN_PROVIDED//

Create Procedure LOADER_ATTACHEDMEMBERS_NORMALIZE_MAP_MEMBERS_WITH_LOGIN_PROVIDED (
    In batchnum int
)
Begin
    Set @id_admin_params = GET_LOADER_INFO('ID_ADMIN_PARAMS', batchnum);

    Update
        LOADER_STATUS sts
        Inner Join LOADER_ATTACHEDMEMBERS src
            On sts.ID_LOADER_STATUS = src.LOADER_STATUS_ID_LOADER_STATUS
        Inner Join MEMBERS mbrs
            On src.MEMBERS_LOGIN = mbrs.MEMBERS_LOGIN
        Inner Join ADMIN_PARAMS admp
            On mbrs.UNIVERS_ID_UNIVERS = admp.UNIVERS_ID_UNIVERS
    Set
        src.ID_MEMBERS = mbrs.ID_MEMBERS
    Where 
        Trim(Coalesce(src.MEMBERS_LOGIN, '')) <> ''
        And admp.ID_ADMIN_PARAMS = @id_admin_params
        And sts.LOADER_STATUS_BATCH_NUM = batchnum 
    ;

End //
Delimiter ;