Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PYODBC存储过程SQL Server-原始CSV输入文件中变量值上的空格-如何进行ecape?_Python_Python 3.x_Pyodbc - Fatal编程技术网

Python PYODBC存储过程SQL Server-原始CSV输入文件中变量值上的空格-如何进行ecape?

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的值中添加单引号,但仍然没有任何进展。 欢迎提供任何提示。文字中的空格不应成为问题。请在

从这个线程开始,如何处理变量中的空格? 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)