我有一个相对简单的查询:
SELECT ATTR.*
FROM NDC_ATTR ATTR
INNER JOIN CONTRACT_NDC_BRG BRG
ON ATTR.ITEM_ID = BRG.CONTRACT_NUM_VAL AND BRG.CONTRACT_NUM_VAL LIKE '%'+@CONTRACT_NUMBER+'%'
JOIN导致数据类型问题:
Conversion failed when converting the varchar value 'Testing' to data type int.
如何在查询期间更改传入的数据类型,以便解决此问题?
答案 0 :(得分:3)
您可以使用CAST或CONVERT
使用CAST:
SELECT ATTR.*
FROM NDC_ATTR ATTR
INNER JOIN CONTRACT_NDC_BRG BRG
ON Cast(ATTR.ITEM_ID as varchar(500)) = BRG.CONTRACT_NUM_VAL AND BRG.CONTRACT_NUM_VAL LIKE '%'+@CONTRACT_NUMBER+'%'