Delimiter //
/**
 * Check that Account Ref is not null
 *
 * @param int batchnum
 * @return void
 * @author Ben
 */
Drop Procedure if exists LOADER_CREDITLIMIT_NORMALIZE_CHECK_ACCOUNT_PROVIDED //
Create Procedure LOADER_CREDITLIMIT_NORMALIZE_CHECK_ACCOUNT_PROVIDED (
    In batchnum int
)
Begin
    Set @lcnap_batchnum = batchnum;
    Update
        LOADER_STATUS sts
        Inner Join LOADER_CREDITLIMIT lc
            On sts.ID_LOADER_STATUS = lc.LOADER_STATUS_ID_LOADER_STATUS
    Set
        sts.LOADER_STATUS_ERRCOUNT = sts.LOADER_STATUS_ERRCOUNT + 1
        , sts.LOADER_STATUS_ERRMSGS =  LOADER_CONCAT_ERR(sts.LOADER_STATUS_ERRMSGS, 'Ni la référence de compte ni le siren/siret ne sont fournis')
    Where
        sts.LOADER_STATUS_BATCH_NUM = @lcnap_batchnum 
        And Trim(Coalesce(lc.ACCOUNTS_REF, '')) = ''
        And Trim(Coalesce(lc.CONTACTS_BUSINESS_SIRET, '')) = ''
    ;
--     Set @flagCountField='LOADER_CREDITLIMIT_ERRCOUNT';
--     Set @flagMsgField='LOADER_CREDITLIMIT_ERRMSGS';
--     Set @lastStatusField=null;
--     Set @lastStatus=null;
--     Set @checkedFieldName = 'ACCOUNTS_REF';
-- 
--     CALL LOADER_CHECK_NULL (
--         'LOADER_CREDITLIMIT'
--         , @checkedFieldName
--         , 'LOADER_CREDITLIMIT_BATCH_NUM'
--         , batchnum
--         , @flagCountField
--         , @flagMsgField
--         , @lastStatusField
--         , @lastStatus
--     );
End //
Delimiter ;