Mario Geuenich
Mario Geuenich

Reputation: 304

Function sequence error (0) (SQLFetch) - SQL, Pyodbc

for _item in file_list:
    for col in cursor.execute("select column1,column2 from tbl"):
        if _item[0]==col.column1:
            #I also tried using a different cursor, still doesn't work
            var1 = cursor.execute("select column2 from tbl where column1=?", _item[0])
            for i in var1: var2 = i[0]
            try:
                cursor3.execute("insert into tbl(column2,column1,column3,column4) values (?,?,?,?)", (var1, _item[0],_item[1],_item[2]))
                cursor3.commit() 
            except IOError as error:
                print error

What i am trying to do is compare the values in a list and the ones from column1, if they match, get the value from column2 on the same row, then add a new line with the value from column2 but different values for the remaining ones.

But unfortunately it doesen't work the way i did it, when running the code above python throws the error:

Error: ('HY010', '[HY010] [Microsoft][ODBC Driver Manager] Function sequence error (0) (SQLFetch)')

In line:

for columnrow in cursor.execute("select column1,column2 from tbl")

Upvotes: 2

Views: 15988

Answers (1)

mechanical_meat
mechanical_meat

Reputation: 169464

What you're doing is fine and should work per @ScottMorken's comment to this answer.


Old answer:
You need to retrieve the results of the query using, for example, .fetchall()
So instead of that line you could do:

for columnrow in cursor.execute("select column1,column2 from tbl").fetchall():
    ...

Upvotes: 4

Related Questions