Delimiter //
/**
 * Find the id of the given account
 * 
 */
Drop Procedure If Exists LOADER_SUMMARIES_NORMALIZE_MAP_DF_SUMM_CODE//
Create Procedure LOADER_SUMMARIES_NORMALIZE_MAP_DF_SUMM_CODE(
    In batchnum Int
)
Begin
--     Set @idEntities = GET_LOADER_INFO('ID_ENTITIES', batchnum);
	Set @idAdminParams = GET_LOADER_INFO('ID_ADMIN_PARAMS', batchnum);

    Update
        LOADER_STATUS S
        Inner Join
            LOADER_SUMMARIES ARD
            On ARD.LOADER_STATUS_ID_LOADER_STATUS = S.ID_LOADER_STATUS
        Inner Join DF_SUMMARIES DFSM
            On ARD.DF_SUMMARIES_CODE = DFSM.DF_SUMMARIES_CODE
			And DFSM.ADMIN_ID_ADMIN = @idAdminParams
    Set
        ARD.DF_SUMMARIES_ID_DF_SUMMR = DFSM.ID_DF_SUMMARIES
		, ARD.DF_PRIORITY_ID_DF_PRIORITY = DFSM.DF_PRIORITY_ID_DF_PRIORITY
    Where
        S.LOADER_STATUS_BATCH_NUM = batchnum
    ;

    -- maj des erreur

    Update
        LOADER_STATUS S
        Inner Join
            LOADER_SUMMARIES ARD
            On ARD.LOADER_STATUS_ID_LOADER_STATUS = S.ID_LOADER_STATUS
    Set
        S.LOADER_STATUS_ERRCOUNT = S.LOADER_STATUS_ERRCOUNT + 1
        , S.LOADER_STATUS_ERRMSGS = LOADER_CONCAT_ERR(S.LOADER_STATUS_ERRMSGS, Concat('Catégorie d''historique inexistante :', ARD.DF_SUMMARIES_CODE ) )
    Where 
        S.LOADER_STATUS_BATCH_NUM = batchnum
        And Coalesce(ARD.DF_SUMMARIES_CODE, '') != ''
        And ARD.DF_SUMMARIES_ID_DF_SUMMR Is Null
    ;

End//
Delimiter ;