【发布时间】:2013-04-09 04:07:19
【问题描述】:
我正在使用 pyodbc 从 Microsoft SQL Server 检索数据。查询格式如下
SET NOCOUNT ON --Ignore count statements
CREATE TABLE mytable ( ... )
EXEC some_stored_procedure
INSERT mytable
--Perform some processing...
SELECT *
FROM mytable
存储过程对包含NULLs 的值执行一些聚合,从而发出Warning: Null value is eliminated by an aggregate or other SET operation. 形式的警告。这会导致 pyodbc 无法检索数据并显示错误消息 No results. Previous SQL was not a query.
我尝试通过设置SET ANSI_WARNINGS OFF 来禁用警告。但是,查询随后会失败并显示错误消息 Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query.。
可以吗
- 禁用警告
- 还是让 pyodbc 忽略警告?
请注意,我没有更改存储过程的权限。
【问题讨论】:
-
语句之间不需要分号吗?
;?我是真心问的。我不知道。 -
@JoeFrambach:不,不需要分号。
标签: python sql-server pyodbc