1

我正在使用 pypyodbc 连接到 SQL Server。我想将我的结果集存储到一个临时表中,就像我们在 SQL 中所做的那样。但是每次我尝试这样做时-我都会收到以下错误消息:

pypyodbc.ProgrammingError: ('24000', '[24000] [Microsoft][ODBC SQL Server Driver]无效游标状态')

这就是我要查询的内容:

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

1 回答 1

4

查询

SELECT id into #temp from Team

不返回结果集;它只是创建#temp表。您现在需要从#temp表中选择以查看结果,即类似于

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])
于 2015-09-22T17:05:27.637 回答