0

在 pyodbc 和 ceodbc 中,声明一个表变量,向其中插入一些数据,然后从中选择似乎不起作用。

cursor.execute("""
DECLARE @LOG TABLE 
    (ID varchar(10))

INSERT INTO @LOG (ID)

SELECT TOP 10 ID
FROM NAME

SELECT ID
FROM @LOG
""")

------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
ProgrammingError: No results.  Previous SQL was not a query.

我想知道这是否是一个真正的问题,或者是否有使它起作用的技巧。SELECT 语句在我的设置中始终运行良好。

4

1 回答 1

0

哦。:oP

cursor.execute("""

SELECT ID
FROM 

(SELECT TOP 10 ID
FROM NAME)

LOG

""")

In [49]: cursor.fetchall()
Out[49]: 
[('1', ),
 ('10', ),
 ('100000', ),
 ('100001', ),
 ('100002', ),
 ('100003', ),
 ('100004', ),
 ('100005', ),
 ('100006', ),
 ('100007', )]
于 2012-12-20T00:12:14.180 回答