1
在我的存储过程,我使用动态查询。我传递参数@nameid int
转换失败转换将varchar值 '其中名_ID在(' 为int数据类型。</strong></p>当 <p>错误</p> <p><strong>转换失败
的where语句是抛出错误。
@strWhere = ' where name_id in ('[email protected]+') and timeid=10'
时
在我的存储过程,我使用动态查询。我传递参数@nameid int
转换失败转换将varchar值 '其中名_ID在(' 为int数据类型。</strong></p>当 <p>错误</p> <p><strong>转换失败
的where语句是抛出错误。
@strWhere = ' where name_id in ('[email protected]+') and timeid=10'
时
@strWhere = ' where name_id in ('+ cast(@nameid as varchar) +') and timeid=10'
为何如此,name_id列的数据类型为int。 –
'int'不是'string'。您必须将该数字转换为字符串。然后你可以把两个琴弦放在一起。 SQL Server不会自动将数字转换为字符串来添加它们。他们是你试图添加的2种不同的类型。 –
@mhasan - 也许*列*的类型为'int',但此时你只是试图创建一个字符串。当使用'+'运算符时,SqlServer不会自动将int('@ nameid')转换为字符串,而是尝试相反:将字符串文字转换为int。这是错误来自哪里。 –