1

I'm using pypyodbc to connect to the SQL Server. I want to store my resultset into a temporary table like we do in SQL. But everytime I try to do it - I get this error message:

pypyodbc.ProgrammingError: ('24000', '[24000] [Microsoft][ODBC SQL Server Driver]Invalid cursor state')

This is what I'm trying to query:

querytest = "SELECT id into #temp from Team"
cursor1.execute(querytest);
var = cursor1.fetchall()
print(var[:10])
0

1 Answer 1

6

The query

SELECT id into #temp from Team

does not return a result set; it just creates the #temp table. You now need to SELECT from the #temp table in order to see the results, i.e., something like

querytest = "SELECT id into #temp from Team"
cursor1.execute(querytest);  # no result set returned
cursor1.execute("SELECT id FROM #temp")  # result set returned here
var = cursor1.fetchall()
print(var[:10])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.