Delimiter //
/**
* In batchnum Int : num du lot, si 0 ou null traitement de l'ensembles des lignes
*/

Drop Procedure if exists LOADER_MEMBERSACCRED_COPY//

Create Procedure LOADER_MEMBERSACCRED_COPY (
    In batchnum int
)
Begin
-- 
    insertQuerys: Begin
        set @batchnum  = batchnum;
        call CASH_AUTOINCREMENT_VALUE('ENTITIES_has_MEMBERS', @lastEnttHasMembersId);

        call LOADER_MEMBERSACCRED_ENTITIES_HAS_MBR_UPDATE(@batchnum);

        call LOADER_MEMBERSACCRED_ENTITIES_HAS_MBR_INSERT (@batchnum, @lastEnttHasMembersId);
        
        Call LOADER_MEMBERSACCRED_REF_DATA_INSERT (@batchnum, 1, @lastRefDataId);
        Call LOADER_MEMBERSACCRED_ENTITIES_HAS_MBR_HAS_REFDATA_INSERT (@batchnum, 1, @lastEnttHasMembersId, @lastRefDataId);
    
        Call LOADER_MEMBERSACCRED_REF_DATA_INSERT (@batchnum, 2, @lastRefDataId);
        Call LOADER_MEMBERSACCRED_ENTITIES_HAS_MBR_HAS_REFDATA_INSERT (@batchnum, 2, @lastEnttHasMembersId, @lastRefDataId);
    
        Call LOADER_MEMBERSACCRED_REF_DATA_INSERT (@batchnum, 3, @lastRefDataId);
        Call LOADER_MEMBERSACCRED_ENTITIES_HAS_MBR_HAS_REFDATA_INSERT (@batchnum, 3, @lastEnttHasMembersId, @lastRefDataId);
    
        Call LOADER_MEMBERSACCRED_REF_DATA_INSERT (@batchnum, 4, @lastRefDataId);
        Call LOADER_MEMBERSACCRED_ENTITIES_HAS_MBR_HAS_REFDATA_INSERT (@batchnum, 4, @lastEnttHasMembersId, @lastRefDataId);
    
        Call LOADER_MEMBERSACCRED_REF_DATA_INSERT (@batchnum, 5, @lastRefDataId);
        Call LOADER_MEMBERSACCRED_ENTITIES_HAS_MBR_HAS_REFDATA_INSERT (@batchnum, 5, @lastEnttHasMembersId, @lastRefDataId);
    

    end ;
End //

Delimiter ;