我正在尝试编写查询但收到错误:无法绑定多部分标识符“dlv.delivery_num”。
我无法弄清楚查询究竟出了什么问题。有人可以调查一下。
以下是查询:
DELETE
答案 0 :(得分:2)
<强>问题强>
UNION
的第二部分没有别名dlv
SELECT
后的UNION
语句低于WHERE
条件。
AND dlv.delivery_num IN ( 'D631239-S354', 'D631372-S558' )
但是,您的FROM
部分没有任何表格别名dlv
。
答案 1 :(得分:0)
您在第二个查询中没有别名dlv
的问题,请参阅以下代码:
SELECT shpUID.attribute_value shipunitid,
pal.container_id palletid,
cas.container_id caseid,
dl.delivery_line_id,
po.attribute_value po,
Max(Isnull(comm.attribute_value, '')) commodity,
Sum(Isnull(Cast(wgt.attribute_value AS FLOAT), 0.0)) weight,
Sum(Isnull(Cast(vol.attribute_value AS FLOAT), 0.0)) volume
FROM container pal
INNER JOIN container cas ON pal.container_id = cas.parent_container_id AND pal.container_type = 'Pallet' AND cas.container_type = 'Case'
INNER JOIN container_detail cdtl ON cdtl.container_id = cas.container_id
INNER JOIN container_delivery cd ON cd.detail_id = cdtl.detail_id
INNER JOIN delivery_line dl ON cd.delivery_line_id = dl.delivery_line_id
INNER JOIN delivery dlv ON dlv.delivery_num = dl.delivery_num
LEFT OUTER JOIN attribute shpUID ON shpUID.attribute_id = cdtl.attribute_id AND shpUID.attribute_type = 'SHIP_UNIT_ID'
LEFT OUTER JOIN attribute wgt ON wgt.attribute_id = cdtl.attribute_id AND wgt.attribute_type = 'Weight'
LEFT OUTER JOIN attribute vol ON vol.attribute_id = cdtl.attribute_id AND vol.attribute_type = 'Volume'
LEFT OUTER JOIN attribute comm ON comm.attribute_id = cdtl.attribute_id AND comm.attribute_type = 'COMMODITY'
LEFT OUTER JOIN attribute po ON po.attribute_id = cdtl.attribute_id AND po.attribute_type = 'PO'
WHERE pal.container_id = '00007712120038613557'
AND dlv.delivery_num IN ( 'D631239-S354', 'D631372-S558' )
AND dlv.delivery_type_id = 'OUTBOUND'
GROUP BY pal.container_id,
cas.container_id,
dl.delivery_line_id,
shpUID.attribute_value,
po.attribute_value
UNION
SELECT shpUID.attribute_value shipunitid,
pal.container_id palletid,
'UNKNOWN' caseid,
dl.delivery_line_id,
po.attribute_value po,
Max(Isnull(comm.attribute_value, '')) commodity,
Sum(Isnull(Cast(wgt.attribute_value AS FLOAT), 0.0)) weight,
Sum(Isnull(Cast(vol.attribute_value AS FLOAT), 0.0)) volume
FROM container pal
INNER JOIN container_detail cdtl
ON cdtl.container_id = pal.container_id
AND pal.container_type = 'Pallet'
INNER JOIN container_delivery cd
ON cd.detail_id = cdtl.detail_id
INNER JOIN delivery_line dl
ON cd.delivery_line_id = dl.delivery_line_id
INNER JOIN delivery dlv ON dlv.delivery_num = dl.delivery_num
LEFT OUTER JOIN attribute shpUID
ON shpUID.attribute_id = cdtl.attribute_id
AND shpUID.attribute_type = 'SHIP_UNIT_ID'
LEFT OUTER JOIN attribute wgt
ON wgt.attribute_id = cdtl.attribute_id
AND wgt.attribute_type = 'Weight'
LEFT OUTER JOIN attribute vol
ON vol.attribute_id = cdtl.attribute_id
AND vol.attribute_type = 'Volume'
LEFT OUTER JOIN attribute comm
ON comm.attribute_id = cdtl.attribute_id
AND comm.attribute_type = 'COMMODITY'
LEFT OUTER JOIN attribute po
ON po.attribute_id = cdtl.attribute_id
AND po.attribute_type = 'PO'
WHERE pal.container_id = '00007712120038613557'
AND dlv.delivery_num IN ( 'D631239-S354', 'D631372-S558' )
AND dlv.delivery_type_id = 'OUTBOUND'
GROUP BY pal.container_id,
dl.delivery_line_id,
shpUID.attribute_value,
po.attribute_value