Work with two cursors on the same connection

0

I need to read two tables in the database so I can compare them later, the code I made is giving error, because I'm passing two queries on 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)
    
asked by anonymous 02.05.2018 / 22:21

1 answer

0

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

    
22.05.2018 / 14:41