我收到此错误:
第245级状态1线10的消息
时,转换失败
将nvarchar值“ PLANT001”转换为数据类型int
我尝试将convert和强制转换为int的方法添加到出现错误的第一行以及最后一个连接处,但是我仍然收到错误。
SELECT
hh.PlantID AS 'Plant ID',
hh.ERP AS 'ERP',
hh.ShipViaID AS 'Ship Via ID',
cc.carrier AS 'Carrier',
cc.service AS 'Service',
cc.packagetype AS 'Pkg Type',
hd.HandlingChargeTypeID AS 'Handling Charge ID',
hd.HandlingCharge 'Handling Charge',
hr.AdditionalPercentageAdded 'Heading Addl % Added',
hd.ApplyToEachPackage AS 'Apply to Each Pkg',
hr.MinimumHandlingCharge AS 'Min Handling Charge',
hr.MaximumHandlingCharge AS 'Max Handling Charge'
FROM
HandlingChargeHeader hh
JOIN
HandlingChargeDetails hd ON hd.HandlingChargeHeaderID = hh.ID
JOIN
HandlingChargeRequirements hr ON hh.ID = hr.HandlingChargeHeaderID
LEFT JOIN
xcarrier_codes cc ON cc.ID = hh.ShipViaID AND hh.PlantID = cc.plantid
cc.plantid
= nvarchar
,hh.plantid
= int
答案 0 :(得分:0)
您可以使用try_convert()
:
select . . .
from . . .
on . . and
try_convert(int, cc.plantid) = cc.plantid;
但是,这似乎无法解决您的问题,无论何时需要数据,都需要始终进行转换。
建议的解决方案是立即更改数据模型。