Python Forum
Reading SQL scripts from excel file and run it using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading SQL scripts from excel file and run it using python
#1
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
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)
Reply


Messages In This Thread
Reading SQL scripts from excel file and run it using python - by saravanatn - Aug-22-2020, 06:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python openyxl not updating Excel file MrBean12 1 337 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Copy Paste excel files based on the first letters of the file name Viento 2 442 Feb-07-2024, 12:24 PM
Last Post: Viento
Sad problems with reading csv file. MassiJames 3 643 Nov-16-2023, 03:41 PM
Last Post: snippsat
  Search Excel File with a list of values huzzug 4 1,248 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Updating sharepoint excel file odd results cubangt 1 843 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  trouble reading string/module from excel as a list popular_dog 0 428 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  Reading a file name fron a folder on my desktop Fiona 4 918 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  Trying to us python.exe from our network to run scripts cubangt 3 871 Aug-17-2023, 07:53 PM
Last Post: deanhystad
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,111 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Save and Close Excel File avd88 0 3,069 Feb-20-2023, 07:19 PM
Last Post: avd88

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020