Python Forum
iterate through query result
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iterate through query result
#1
I am trying to take data from a database and put it in an excel spreadsheet.

##################################
with connection.cursor() as cursor:
        # Select a record
        sql = "SELECT DISTINCT JobID FROM tblDTTicket WHERE Ticket_Date = '2020-03-24'"

        cursor.execute(sql)
        jobs = cursor.fetchall()
        joblist.append(cursor.execute(sql))

    for job in jobs:
        print(job)

finally:
    connection.close()
#####################

EXAMPLE OF OUTPUT
Output:
{'JobID': 'STOCK7'} {'JobID': 'STOCK2'} {'JobID': 'STOCK5'}
I keep trying to assign the data to a cell, I am using openpyxl and trying to pass even one of these three pieces of data to a cell.

I have tried:

ws['A1']=job[0]
ws['A1']=joblist[0] #After appending an empty joblist[]

I could use a point in the right direction...
Reply


Messages In This Thread
iterate through query result - by bigt - Mar-25-2020, 06:16 PM
RE: iterate through query result - by bigt - Mar-25-2020, 07:55 PM
RE: iterate through query result - by deanhystad - Mar-25-2020, 08:03 PM
RE: iterate through query result - by bigt - Mar-25-2020, 08:14 PM
RE: iterate through query result - by deanhystad - Mar-25-2020, 09:28 PM
RE: iterate through query result - by bigt - Mar-25-2020, 11:12 PM
RE: iterate through query result - by bigt - Mar-26-2020, 02:27 PM
RE: iterate through query result - by deanhystad - Mar-26-2020, 03:53 PM
RE: iterate through query result - by buran - Mar-26-2020, 03:57 PM
RE: iterate through query result - by bigt - Mar-26-2020, 04:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Write SQLite query result to file hjk6734 1 2,724 May-27-2020, 12:17 PM
Last Post: menator01
  python code (embedded in Redshift) to return result of the query Mel 0 2,936 Aug-24-2018, 06:12 PM
Last Post: Mel

Forum Jump:

User Panel Messages

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