Work with two cursors on the same connection

Asked

Viewed 38 times

0

I need to read two tables in the database in order to compare them later, the code I did this giving error, because I am going through two queries in the same connection how could I be correcting this? Thank you.

import pyodbc
conn = pyodbc.connect("DRIVER={SQL Server};Server=localhost;database=teste;uid=;pwd=")

cursor1 = conn.cursor()

cursor1.execute("select top 10 * from tab1")

cursor2 = conn.cursor()

cursor2.execute("select top 10 * from tab2")    

for row in cursor1:
   print(row)

for row in cursor2:
    print(row)

1 answer

0

You can fix this without infinitive + gerund. Simply assign each query to a variable using fetchAll() and then compare the variables.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.