我正在尝试使用pyodbc运行以下存储过程。
USE [CompanyMC]
GO
/****** Object: StoredProcedure [dbo].[marketprice] Script Date: 15/10/2019 23:02:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[marketprice](@marketvalue AS VARCHAR(30))
AS
BEGIN
SELECT TRY_CAST (CompanyMarketCap AS numeric) from CompanyMC.dbo.Companies
where CompanyName= @marketvalue
END
这是我的python代码
# Call the procedure and pass rhe arguments as a list
sql=f"""\
EXEC {proc_name} @marketvalue=?;
"""
parameters = (company_name)
cursor.execute(sql, parameters)
# get the result set and iterate over it to get the returned value
result = cursor.fetchval()
我一直遇到错误。
('42000','[42000] [Microsoft] [用于SQL Server的ODBC驱动程序17] [SQL Server]将数据类型varchar转换为数字时出错。(8114(SQLExecDirectW)')
似乎无法弄清楚哪里做错了任何提示。