我在表2中有数据,我需要将其用作检索表1中信息的关键字。表2包含有关零件编号的信息,包括其制造工厂和生产过程。我需要将仓库(工厂)和零件号传递给Table2,并将其,生产工厂ID和流程ID传回给我。我尝试使用下面的SQL,但是它引发了一个语法错误,该错误仅表示“ JOIN操作中的语法错误”。我宁愿不必拆分成单独的sql语句:/
SELECT
T1.MFRFMR03 AS Seq,
T1.MFRFMR04 AS [Desc],
T1.MFRFMR0S AS M2M,
T1.MFRFMR0Q AS Std_Labor,
T1.MFRFMR0M AS Std_Setup,
T1.MFRFMR0R AS Std_Units
FROM
T1 LEFT JOIN
(
SELECT
T2.MAJRTEPLT,
T2.MAJRTEID
FROM
T2
WHERE
(
((T2.PLT)=[Enter Plant Number])
AND
((T2.ITMID)=ucase$([Enter Part Number]))
)
) ON ((T1.MFRFMR01)=(T2.MAJRTEPLT)) AND ((T1.MFRFMR02)=(T2.MAJRTEID))
WHERE
(
((T1.MFRFMR0Q)<>0)
AND
((T1.MFRFMR0I)<>'S')
AND
((T1.MFRFMR0G)=0)
OR
((T1.MFRFMR0G)=99999)
AND
(
((T1.MFRFMR01)=(T2.MAJRTEPLT))
AND
((T1.MFRFMR02)=(T2.MAJRTEID))
EXISTS IN
)
)
ORDER BY
T1.MFRFMR03;
答案 0 :(得分:1)
这是因为您的子查询没有别名。在子查询中使用的T2仅在这些括号内可见。
SELECT
T1.MFRFMR03 AS Seq,
T1.MFRFMR04 AS [Desc],
T1.MFRFMR0S AS M2M,
T1.MFRFMR0Q AS Std_Labor,
T1.MFRFMR0M AS Std_Setup,
T1.MFRFMR0R AS Std_Units
FROM
T1 LEFT JOIN
(
SELECT
T2.MAJRTEPLT,
T2.MAJRTEID
FROM
T2
WHERE
(
((T2.PLT)=[Enter Plant Number])
AND
((T2.ITMID)=ucase$([Enter Part Number]))
)
) SUBQ ON ((T1.MFRFMR01)=(SUBQ.MAJRTEPLT)) AND ((T1.MFRFMR02)=(SUBQ.MAJRTEID))
...