Delimiter //
/**
 * Due date is not provided -> initialize with the entry's date
 * 
 * @author Jean-François
 * @ticket #3823
 */ 
Drop Procedure If Exists LOADER_ENTRIES_NORMALIZE_MAP_DUEDATE_NOTPROVIDED//
Create Procedure LOADER_ENTRIES_NORMALIZE_MAP_DUEDATE_NOTPROVIDED(
    In batch_num Int
)
Begin

    Update
        LOADER_ENTRIES E
        Inner Join LOADER_STATUS S
            On E.LOADER_STATUS_ID_LOADER_STATUS = S.ID_LOADER_STATUS
    Set
        E.ENTRIES_DUE_DATE = E.ENTRIES_DATE
    Where
        S.LOADER_STATUS_BATCH_NUM = batch_num
        And E.ID_ENTRIES_NEW Is Not Null
        And Coalesce(E.ENTRIES_DUE_DATE, '') = ''
    ;

End//
Delimiter ;