转换nvarchar时转换失败

时间:2018-04-02 20:56:00

标签: sql sql-server

有人可以在此声明中协助我下面的错误

SELECT 
    sh.INTERNAL_SHIPMENT_NUM,sh.shipment_id, sh.carrier,  
    sh.carrier_service,sh.carrier_type,sh.route,sh.customer_name,sh.total_lines,
    sh.total_weight,sh.total_volume,sh.SCHEDULED_SHIP_DATE AS SCHEDULED_SHIP_DATE,sh.total_qty,sh.trailing_sts,
    CASE 
       WHEN sh.CUSTOMER IN (46003204, 30321) 
          THEN 'CHUB' 
          ELSE '' 
    END AS CUSTOMER,
    (SELECT TOP 1 sd.customer_po 
     FROM shipment_detail sd 
     WHERE sd.internal_shipment_num = sh.internal_shipment_num
     ORDER BY sd.CUSTOMER_PO desc) as CUSTOMER_PO, 
    SH.REJECTION_NOTE
FROM
    shipment_detail sd
INNER JOIN 
    shipment_header_view sh ON sd.INTERNAL_SHIPMENT_NUM = sh.INTERNAL_SHIPMENT_NUM
LEFT OUTER JOIN 
    RYDI_orders RO ON SH.SHIPMENT_ID = RO.DELIVERY_id
WHERE 
    sh.leading_sts = 100 AND sh.trailing_sts = 100
GROUP BY
    sh.INTERNAL_SHIPMENT_NUM,sh.shipment_id, sh.carrier, 
    sh.carrier_service, sh.carrier_type, sh.customer,
    sh.route, sh.customer_name, sh.total_lines,
    sh.total_weight, sh.total_volume, sh.SCHEDULED_SHIP_DATE,
    sh.total_qty, sh.trailing_sts, SH.REJECTION_NOTE

错误:

  

Msg 245,Level 16,State 1,Line 1
  将nvarchar值'50310H'转换为数据类型int时,转换失败。

1 个答案:

答案 0 :(得分:0)

我的钱是加入或where子句作为你的问题。我会提供可能有用的调试建议,因为我无法发表评论。 识别:如果您知道50310H是什么,如果是货号或其他什么,您可以更快地找到它并比较两个表中的字段。另一个选择是只比较表属性并查看字段是什么。可能有两个表正在尝试匹配的值,但一个是int,一个是nvarchar。 要解决:最终的解决方案是 cast(whateverintfield as nvarchar) 一旦你确定了罪犯,就阻止它与你争论。祝好运。