Delimiter //
/**
 * Clone table, used for contacts
 */ 
Drop Procedure if exists LOADER_POPULATE_TABLE_ACCOUNTS_REPLICATION//
Create Procedure LOADER_POPULATE_TABLE_ACCOUNTS_REPLICATION(
    In batchnum Int
)
Begin
    
    Insert Into LOADER_ACCOUNTS_REPLICATION (
        LOADER_STATUS_ID_LOADER_STATUS
        , ID_ACCOUNTS
        , ID_ACCOUNTS_NEW
        , LOADER_ACCOUNTS_ID_LOADER_ACCOUNTS
    )
    Select
        LA.LOADER_STATUS_ID_LOADER_STATUS
        , LA.ID_ACCOUNTS
        , LA.ID_ACCOUNTS_NEW
        , ID_LOADER_ACCOUNTS
    From
        LOADER_ACCOUNTS LA
        Inner join LOADER_STATUS LS
            ON LA.LOADER_STATUS_ID_LOADER_STATUS = LS.ID_LOADER_STATUS
    Where 
        LS.LOADER_STATUS_BATCH_NUM = batchnum
    ;

End //
Delimiter ;
