SQL多部分标识符错误

时间:2012-09-13 05:47:53

标签: sql sql-server sql-server-2008

这是我简单的sql代码。在执行其抛出和错误时。

无法绑定多部分标识符“product_hscodes.hscode”。

select DISTINCT mi.*,csq.contract_code
  from master_items mi
  join contract_shipment_qty csq on csq.item_code = mi.code
  join contract c on c.code = csq.contract_code
  join master_item_products mp on mp.master_item = mi.id
  join hscode h on h.code = product_hscodes.hscode
 where csq.shipment_id = 6
   and csq.contract_code = '046V-12-A04-05'
   and mi.code = 'M165'
   and h.code = '12345'

1 个答案:

答案 0 :(得分:1)

您尚未加入product_hscodes表。

from master_items mi
join contract_shipment_qty csq on csq.item_code = mi.code
join contract c on c.code = csq.contract_code
join master_item_products mp on mp.master_item = mi.id

join product_hscodes 
     on product_hscodes.fk = <primary table>.pk //<<Have you joined this table?

join hscode h on h.code = product_hscodes.hscode