Python PYODBC存储过程SQL Server-原始CSV输入文件中变量值上的空格-如何进行ecape?
从这个线程开始,如何处理变量中的空格? e、 g 在上面的示例中,@TestResult将在CSV文件第3列中具有值“通过测试” 我尝试过以下方法,但毫无乐趣: @TestResult=''?'',@TestResult=''?'',@TestResult=[?],它们都给出pyodbc.ProgrammingError:(“SQL包含2个参数标记,但提供了3个参数”,“HY000”) 我甚至尝试在输入CSV的值中添加单引号,但仍然没有任何进展。Python PYODBC存储过程SQL Server-原始CSV输入文件中变量值上的空格-如何进行ecape?,python,python-3.x,pyodbc,Python,Python 3.x,Pyodbc,从这个线程开始,如何处理变量中的空格? e、 g 在上面的示例中,@TestResult将在CSV文件第3列中具有值“通过测试” 我尝试过以下方法,但毫无乐趣: @TestResult=''?'',@TestResult=''?'',@TestResult=[?],它们都给出pyodbc.ProgrammingError:(“SQL包含2个参数标记,但提供了3个参数”,“HY000”) 我甚至尝试在输入CSV的值中添加单引号,但仍然没有任何进展。 欢迎提供任何提示。文字中的空格不应成为问题。请在
欢迎提供任何提示。文字中的空格不应成为问题。请在qmarks没有标点符号的地方发布您发布的代码中的确切错误,而不是您的尝试。nvarchar(10)`后面的逗号看起来是错误的。@GordThompson是,我删除了一些参数以简化它,忘记删除逗号。在存储过程定义中,<代码> @测试结果< /代码>偶然被声明为输出参数?好吧,算了出来。CSV文件中的值采用UTF-8编码,存储过程中的值采用Ansi格式。当比较这两个字符串时,它们是不同的。
for CustomerID,TestCode,TestResult in csv_input:
#query
query = """\
SET NOCOUNT ON;
Declare @CustomerID nvarchar(100),
@TestCode nvarchar(20),
@TestResult nvarchar(10),
exec TestData.sp_uat_TestData_Customer @CustomerID = ? , @TestCode = ?, @TestResult = ?;"""
#set the ID as per the iteration of the loop
args = (CustomerID,TestCode,TestResult,)
#execute the query above using the provided variable
cursor.execute(query,args)
# print out the data returned by the Stored Procedure
for row in cursor:
print(row)
csv_output.writerow(row)