go to post Jim Cooper · Nov 13, 2024 Solved: exp_sql = "select rundate, filename, batchid, starttimestamp, endtimestamp, lastname, firstname, birthdate from src_tbl" ins_sql = "insert into dest_tbl (rundate, filename, batchid, starttimestamp, endtimestamp, lastname, firstname, birthdate) values (?, ?, ?, ?, ?, ?, ?, ?)" date_cols = [0, 3, 4, 7] # create a list of columns are that are of date, time or timestamp type batch_items = 1000 # set number of rows to process at a time try: src_csr.execute(exp_sql) while True: # Fetch a batch of rows from the source table rows = src_csr.fetchmany(batch_size) if not rows: break # Exit loop if no more rows to process if len(date_cols) == 0: # No date/times to deal with in this table tgt_csr.executemany(ins_sql, rows) else: fixed_rows = [] # make a mutable list for row in rows: row_list = list(row) # copy rows to list for date_col in date_cols: # for each date column index if row_list[date_col] is not None: # if value is not None row_list[date_col] = str(row_list[date_col]) # convert to a string, format like %ODBCOUT() fixed_rows.append(row_list) # append the record to rows tgt_csr.executemany(ins_sql, fixed_rows) tgt_cnx.commit() # Commit after each batch