Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ERROR: No results. Previous SQL was not a query

cnxn = pyodbc.connect(driver="{ODBC Driver 17 for SQL Server}", server="xxx", database="yy", user="abc", password="abc")
cursor = cnxn.cursor()

b = alter table temp1 add column3 varchar(10)
cursor.execute(b)
cursor.fetchall()

from the above code I’m trying to alter the table and add the column as i contain 2 tables 1 is existing table and the other is new table the column from the new table as to be added to the exixting table so i have done the code but i got the error of

ERROR: No results. Previous SQL was not a query.

so please help me out to clear this error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

change the line of code to as below

b = 'alter table temp1 add column3 varchar(10);'

this assigns the entire SQL command as string to the variable b, which then you can use in the call to execute() function of the cursor.
Also, the ALTER TABLE SQL statement will not return any results set, so you need not call fetchXX() method after executing it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading