Querying Data
After Connecting, you can execute a SQL statement and retrieve the results.
SELECT Procedure
You will need to obtain a cursor before executing any SQL. Once you have one, you can use the cursor's execute method.
cursor = cnxn.cursor() cursor.execute("SELECT InvoiceId, InvoiceNumber FROM INVOICES WHERE CustomerName = 'NewTech Industries'")
Iterating over the Results
You can use a for loop to iterate over the rows of the resultset. Each row is presented as a tuple containing column values:
for (InvoiceId, InvoiceNumber) in cursor: print("InvoiceId = {}, InvoiceNumber = {}".format(InvoiceId, InvoiceNumber))