Sep-29-2022, 07:32 AM
Hi Buran,
I did what you suggested, code is working fine. thanks again.
I have one question ,
1) if there is no record in sql. does it go in infinite loop, we are not using break condition / checking are there any records.
2) is there any chance of memory full issue if (SQL Table is big one)
below is attempted as code. is this correct now.
I did what you suggested, code is working fine. thanks again.
I have one question ,
1) if there is no record in sql. does it go in infinite loop, we are not using break condition / checking are there any records.
2) is there any chance of memory full issue if (SQL Table is big one)
below is attempted as code. is this correct now.
import pyodbc import csv import os connection = pyodbc.connect( 'DRIVER={ODBC Driver 17 for SQL Server};SERVER=DESKTOP-GQK64O6;DATABASE=Customer;Trusted_Connection=yes;') with connection.cursor() as crsr: qry = "Select * from employee" crsr.execute(qry) folderPath = "C:\\Users\\malle\\OneDrive\\Desktop\\C\\test_data\\output" header = next(zip(*crsr.description)) fname = "main.csv" fullpath = os.path.join(folderPath, fname) with open(fullpath, "w", newline="") as outfile: writer = csv.writer(outfile, delimiter="|", quoting=csv.QUOTE_NONNUMERIC) writer.writerows([header]) for idx, row in enumerate(crsr, start=1): writer.writerows(crsr)