
Delimiter //
Drop Procedure If Exists LOADER_RECLAIMS_NORMALIZE_MAP_MEMBER//
Create Procedure LOADER_RECLAIMS_NORMALIZE_MAP_MEMBER(
    In batchnum Int
)
Begin
	Set @idEntities = GET_LOADER_INFO('ID_ENTITIES', batchnum);
	-- obtention du membre batch
	Set @admin = GET_LOADER_INFO('ID_ADMIN_PARAMS', batchnum);
	Set @IdMEmber  = (Select ID_MEMBERS From MEMBERS Where UNIVERS_ID_UNIVERS = @admin And MEMBERS_ADMIN_RIGHTS = 1 and MEMBERS_LOGIN like '%batch%' limit 1);
	if @IdMEmber Is Null Then
		Set @IdMEmber  = (Select ID_MEMBERS From MEMBERS Where UNIVERS_ID_UNIVERS = @admin And MEMBERS_ADMIN_RIGHTS = 1 limit 1);
	End if;

    Update
        LOADER_STATUS STS
        Inner Join LOADER_RECLAIMS LRD
            On LRD.LOADER_STATUS_ID_LOADER_STATUS = STS.ID_LOADER_STATUS
    Set
        LRD.MEMBERS_ID_MEMBERS = @IdMEmber
    Where
        STS.LOADER_STATUS_BATCH_NUM = batchnum
		And STS.LOADER_STATUS_ERRCOUNT = 0
    ;



End//
Delimiter ;