import pymssql
conn = pymssql.connect(host='SQL01', user='user', password='password', database='mydatabase', as_dict=True)
cur = conn.cursor()
users = cur.execute('SELECT * FROM persons WHERE salesrep=%s', 'John Doe').fetchall()
conn.close()
for row in users:
print "ID=%d, Name=%s" % (row['id'], row['name'])
Try assigning results to something instead of using the cursor.
cur.execute()is a function as such, while it returns (which you see), you can not assign it to anything, so when you go to do the cycle for,.
, ( ) :
import pymssql
conn = pymssql.connect(host='SQL01', user='user', password='password', database='mydatabase', as_dict=True)
cur = conn.cursor()
sql = 'SELECT * FROM persons WHERE salesrep=%s'
for row in cur.execute(sql, 'John Doe').fetchall():
print "ID=%d, Name=%s" % (row['id'], row['name'])
conn.close()
for cur.execute(),
( : fetchall, . )