我正在尝试向MS Access查询添加一个简单的内连接。我试图将表与单个字段连接起来,只是为了将结果限制为cusnums的子集。我收到一个语法错误(见下文),我根本就不明白。
我在下面添加了旧代码和新代码。唯一的变化是添加了内连接。任何帮助,将不胜感激。感谢。
错误讯息:
查询表达式中的语法错误(缺少运算符)
'(qry_Co_1_PRET_Routed_2_Days_Out.cusnum = tbl_Store_With_Sat_Ord.shpcusnum)
LEFT JOIN
qry_Co_1_PRET_Open_Order_2_Days_Out
ON
(qry_Co_1_PRET_Routed_2_Days_Out.co_num = qry_Co_1_PRET_Open_Order_2_Days_Out.co_num)
AND
(qry_Co_1_PRET_Routed_2_Days_Out.cusnum = qry_Co_1_PRET_Open_Order_2_Days_Out.shpcusnum'
旧代码:
SELECT
IIf([totordqty]>0, "Order In","No Order") AS OO_Staus,
qry_Co_1_PRET_Routed_2_Days_Out.co_num,
qry_Co_1_PRET_Routed_2_Days_Out.prislscod,
qry_Co_1_PRET_Routed_2_Days_Out.cusnum,
qry_Co_1_PRET_Routed_2_Days_Out.co_nam,
qry_Co_1_PRET_Routed_2_Days_Out.cusphn,
Switch([totordqty]>0,"",[cusphn]<>"",[cusphn],True,"No Phone # on File") AS Cust_Phone,
qry_Co_1_PRET_Routed_2_Days_Out.rtedow,
qry_Co_1_PRET_Routed_2_Days_Out.rtecod,
qry_Co_1_PRET_Routed_2_Days_Out.stpnum,
qry_Co_1_PRET_Open_Order_2_Days_Out.plnshpdat,
qry_Co_1_PRET_Open_Order_2_Days_Out.totordqty,
qry_Co_1_PRET_Open_Order_2_Days_Out.ordnetwgt,
qry_Co_1_PRET_Open_Order_2_Days_Out.ordcub,
qry_Co_1_PRET_Open_Order_2_Days_Out.shptotamt,
qry_Co_1_PRET_Open_Order_2_Days_Out.prcflg,
qry_Co_1_PRET_Routed_2_Days_Out.cusemaadd,
qry_Co_1_PRET_Routed_2_Days_Out.TD_Email
FROM
qry_Co_1_PRET_Routed_2_Days_Out
LEFT JOIN
qry_Co_1_PRET_Open_Order_2_Days_Out
ON
(qry_Co_1_PRET_Routed_2_Days_Out.co_num = qry_Co_1_PRET_Open_Order_2_Days_Out.co_num)
AND
(qry_Co_1_PRET_Routed_2_Days_Out.cusnum = qry_Co_1_PRET_Open_Order_2_Days_Out.shpcusnum)
WHERE
(((IIf([totordqty]>0,"Order In","No Order"))="No Order"))
ORDER BY
IIf([totordqty]>0,"Order In","No Order"),
qry_Co_1_PRET_Routed_2_Days_Out.rtecod,
qry_Co_1_PRET_Routed_2_Days_Out.stpnum;
新守则:
SELECT
IIf([totordqty]>0,"Order In","No Order") AS OO_Staus,
qry_Co_1_PRET_Routed_2_Days_Out.co_num,
qry_Co_1_PRET_Routed_2_Days_Out.prislscod,
qry_Co_1_PRET_Routed_2_Days_Out.cusnum,
qry_Co_1_PRET_Routed_2_Days_Out.co_nam,
qry_Co_1_PRET_Routed_2_Days_Out.cusphn,
Switch([totordqty]>0,"",[cusphn]<>"",[cusphn],True,"No Phone # on File") AS Cust_Phone,
qry_Co_1_PRET_Routed_2_Days_Out.rtedow,
qry_Co_1_PRET_Routed_2_Days_Out.rtecod,
qry_Co_1_PRET_Routed_2_Days_Out.stpnum,
qry_Co_1_PRET_Open_Order_2_Days_Out.plnshpdat,
qry_Co_1_PRET_Open_Order_2_Days_Out.totordqty,
qry_Co_1_PRET_Open_Order_2_Days_Out.ordnetwgt,
qry_Co_1_PRET_Open_Order_2_Days_Out.ordcub,
qry_Co_1_PRET_Open_Order_2_Days_Out.shptotamt,
qry_Co_1_PRET_Open_Order_2_Days_Out.prcflg,
qry_Co_1_PRET_Routed_2_Days_Out.cusemaadd,
qry_Co_1_PRET_Routed_2_Days_Out.TD_Email
FROM
qry_Co_1_PRET_Routed_2_Days_Out
INNER JOIN
tbl_Store_With_Sat_Ord
ON
(qry_Co_1_PRET_Routed_2_Days_Out.cusnum = tbl_Store_With_Sat_Ord.shpcusnum)
LEFT JOIN
qry_Co_1_PRET_Open_Order_2_Days_Out
ON
(qry_Co_1_PRET_Routed_2_Days_Out.co_num = qry_Co_1_PRET_Open_Order_2_Days_Out.co_num)
AND
(qry_Co_1_PRET_Routed_2_Days_Out.cusnum = qry_Co_1_PRET_Open_Order_2_Days_Out.shpcusnum)
WHERE
(((IIf([totordqty]>0,"Order In","No Order"))="No Order"))
ORDER BY
IIf([totordqty]>0,"Order In","No Order"),
qry_Co_1_PRET_Routed_2_Days_Out.rtecod,
qry_Co_1_PRET_Routed_2_Days_Out.stpnum;
答案 0 :(得分:1)
将SQL代码的FROM
部分更改为:
FROM
(
qry_Co_1_PRET_Routed_2_Days_Out
LEFT JOIN
qry_Co_1_PRET_Open_Order_2_Days_Out
ON
(qry_Co_1_PRET_Routed_2_Days_Out.co_num = qry_Co_1_PRET_Open_Order_2_Days_Out.co_num)
AND
(qry_Co_1_PRET_Routed_2_Days_Out.cusnum = qry_Co_1_PRET_Open_Order_2_Days_Out.shpcusnum)
)
INNER JOIN
tbl_Store_With_Sat_Ord
ON
(qry_Co_1_PRET_Routed_2_Days_Out.cusnum = tbl_Store_With_Sat_Ord.shpcusnum)
WHERE
[totordqty] <= 0
ORDER BY
[totordqty] <= 0,
qry_Co_1_PRET_Routed_2_Days_Out.rtecod,
qry_Co_1_PRET_Routed_2_Days_Out.stpnum;
请注意WHERE
&amp;的更改ORDER BY
条款。