sql server - pyodbc - previous sql was not a query -
i above error while trying insert data table, tried set nocount on option , still have same problem,
import pyodbc p connstr= 'driver={sql server};server=sqlexpress;database=test;trusted_connection=yes;unicode_results=false' conn = p.connect(connstr,charset='utf-16') print conn cursor = conn.cursor() try: result = cursor.execute("""select col1 tb2 (select 1 col1) tb1""") except exception error: print error each in result.fetchall(): print each
you need execute first select [xxx] [new_tablename] [yyy]
tsql statement, read newly created tb2 table.
import pyodbc p connstr= 'driver={sql server};server=.\sqlexpress;database=test;trusted_connection=yes;unicode_results=false' conn = p.connect(connstr,charset='utf-16') print conn cursor = conn.cursor() try: result = cursor.execute("""select col1 tb2 (select 1 col1) tb1""") except exception error: print error try: result = cursor.execute("""select col1 tb2""") except exception error: print error each in result.fetchall(): print each
also, might want change instance name .\sqlexpress
instead of sqlexpress
.
Comments
Post a Comment