Aug-23-2020, 04:49 PM
Thanks Ibreedan
Now python code is working fine. But 2 problem's
1) I am not getting column header name when I run SQL scripts through Python.
2) How to auto increment next row in excel file. E.g If my Cell value is (0,0) and if I want to read the SQL script available in Cell value (1,0) . How to do it ?
Now python code is working fine. But 2 problem's
1) I am not getting column header name when I run SQL scripts through Python.
2) How to auto increment next row in excel file. E.g If my Cell value is (0,0) and if I want to read the SQL script available in Cell value (1,0) . How to do it ?
import xlrd import pyodbc conn = pyodbc.connect('Driver={SQL Server};' 'Server=Servername' 'Database=PythonSQL;' 'Trusted_Connection=yes;') file_location= "E:/Python Automation/file.xls" workbook =xlrd.open_workbook(file_location) sheet =workbook.sheet_by_index(0) query=sheet.cell_value(0,0) cursor = conn.cursor() cursor.execute(query) for row in cursor: print(row)