Aug-01-2019, 11:13 PM
Hi,
Have a bit of code that runs a sql query - can't seem to get it to output to a .csv or an .xlsx file. Any help is appreciated
The window has several buttons, each of which should generate a report. The button label in this example is "Count of All Codes" - just trying to change the last line so that it writes to a file like "C:/mytestfile.csv"
Have a bit of code that runs a sql query - can't seem to get it to output to a .csv or an .xlsx file. Any help is appreciated
The window has several buttons, each of which should generate a report. The button label in this example is "Count of All Codes" - just trying to change the last line so that it writes to a file like "C:/mytestfile.csv"
if event =="Count of All Codes": connstring = 'DRIVER={SQL Server};SERVER=XXX;DATABASE=XXX;UID=XXX;PWD=XXX' SQLStr = "SELECT subsource_type_desc, COUNT(*) AS 'num' FROM [TSCACS] GROUP BY subsource_type_desc order by num desc" conn = pyodbc.connect(connstring) cursor = conn.cursor() cursor.execute(SQLStr) for row in cursor: print(row)Thanks again for any help.