AnsweredAssumed Answered

SQL dump to Excel

Question asked by CCweedcontrol on Jul 13, 2020
Latest reply on Jul 14, 2020 by jborgion

I am trying to do a SQL dump of a table to excel but I can't get past the error, what am I doing wrong?

 

Error line 14

'utf8' codec can't decode byte 0xc3 in position 0: invalid continuation byte

 

import pyodbc
import pandas as pd
import os
cnxn = pyodbc.connect("Driver={SQL Server};"
                      "Server=***;"
                      "Database=***;"
                      "uid=***;pwd=***")
cursor = cnxn.cursor()
script = """
SELECT * FROM ***.***
"""

df = pd.read_sql(script, cnxn)
writer = pd.ExcelWriter(r'C:\Temp\export.xlsx')
df.to_excel(writer, sheet_name ='Sheet1', encoding='utf-8')
writer.save()

Outcomes