Aug-22-2020, 06:13 PM
Hi All,
I placed my SQL scripts in excel file and my python code needs to read the SQL code from excel and then run the SQL code from SQL Server using Python . If the fetch row is greater than zero then it is 'Failed' else 'Passed'. This failed or Passed results needs to be writes into Excel file as output.
What I tried do far . I am able to run the SQL scripts directly
I placed my SQL scripts in excel file and my python code needs to read the SQL code from excel and then run the SQL code from SQL Server using Python . If the fetch row is greater than zero then it is 'Failed' else 'Passed'. This failed or Passed results needs to be writes into Excel file as output.
What I tried do far . I am able to run the SQL scripts directly
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server=ServerName;'
'Database=DatabaseName;'
'Trusted_Connection=yes;')
cursor = conn.cursor()
cursor.execute('SELECT * FROM [DUMMY]')
title = [i[0] for i in cursor.description]
print (title)
for row in cursor:
print(row)I am able to read the excel files separately . When I merge both the code I am getting error from SQL code part import xlrd file_location= "pathname" workbook =xlrd.open_workbook(file_location) sheet =workbook.sheet_by_index(0) sheet.cell_value(0,0)
