Apr-17-2018, 04:23 PM
The below code works however, whenever it gets exported, the headers for each column is missing. I need it to include all headers please advise
import pyodbc
import csv
conn =("Driver={SQLSERVER Native Client 11.0};"
"Server = blah"
"database = mydb;"
cursor = coon.cursor()
sql = """Select top 5 * from mytable"""
cursor.execute(sql)
row = cursor.fetchall()
with open('test.csv', 'w', newline= '') as f:
a = csv.writer(f, delimiter=',')
a.writerows(rows
cursor.close()
import pyodbc
import csv
conn =("Driver={SQLSERVER Native Client 11.0};"
"Server = blah"
"database = mydb;"
cursor = coon.cursor()
sql = """Select top 5 * from mytable"""
cursor.execute(sql)
row = cursor.fetchall()
with open('test.csv', 'w', newline= '') as f:
a = csv.writer(f, delimiter=',')
a.writerows(rows
cursor.close()