问题描述
我需要使用输入参数名称通过pyodbc
模块从python2.7
调用SqlServer存储过程
.
I need to call a SqlServer stored procedure
from python2.7
via pyodbc
module with input parameter name.
我根据输入参数顺序尝试基于 文档:
I tried based on documentation by input parameter order:
它有效,但我需要传递存储过程的参数名称
,因为存储过程输入参数的顺序总是在变化.所以我需要按名称传递它们.
It works, but I need to pass parameter name of stored procedure
because order of stored procedure input parameter always changes. So I need to pass them by name.
然而这行不通.正确的语法是什么?
However this doesn't work. What's the correct syntax?
推荐答案
我在 SQL Server 2008 R2 中使用以下存储过程对此进行了测试:
I tested this using the following stored procedure in SQL Server 2008 R2:
坏消息(CALL")
我发现
给出不一致的结果.
使用 {SQL Server Native Client 10.0}
ODBC 驱动程序,它忽略参数 names 并将参数视为位置参数,产生 ...
With the {SQL Server Native Client 10.0}
ODBC driver it ignored the parameter names and treated the parameters as positional, yielding ...
... 使用旧的 {SQL Server}
ODBC 驱动程序,我刚刚收到错误
... and with the older {SQL Server}
ODBC driver I just got the error
DataError: ('22018', '[22018] [Microsoft][ODBC SQL Server Driver]转换规范的字符值无效 (0) (SQLExecDirectW)')
DataError: ('22018', '[22018] [Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification (0) (SQLExecDirectW)')
好消息(EXEC")
我发现了
使用两个 ODBC 驱动程序给了我以下(正确的)结果
gave me the following (correct) result using both ODBC drivers
这篇关于Python - pyodbc 调用带有参数名称的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!