2012-12-19 65 views
0

在pyodbc和ceodbc中,聲明一個表變量,向其中插入一些數據,然後從中選擇似乎不起作用。在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語句在我的設置中一直正常工作。

回答

0

D'oh。 :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',)]