Delimiter //
/**
 * Clean context to work with a given business table
 *
 * @author Jean-François
 */
Drop Procedure If Exists LOADER_TEST_MOCK_BUSINESS_CLEAN//
Create Procedure LOADER_TEST_MOCK_BUSINESS_CLEAN(
    In tablename Varchar(80)
)
Begin

    Set @tablenameTest = Concat('test_', Coalesce(tablename, ''));

    Call CASH_ISTABLE(@tablenameTest, @exists);
    If Coalesce(@exists, 0) > 0 Then

        Set FOREIGN_KEY_CHECKS = 0;

        -- copy values
        Set @query = Concat('Replace Into ', Coalesce(tablename,''),' Select * From ', @tablenameTest );
        Prepare stmt from @query;
        Execute stmt;
        Deallocate prepare stmt;

        -- delete temporary table
        Set @query = Concat('Drop Temporary Table ', @tablenameTest);
        Prepare stmt from @query;
        Execute stmt;
        Deallocate prepare stmt;

        Set FOREIGN_KEY_CHECKS = 1;

    End If;

End//
Delimiter ;