我是新手使用Access并尝试更改此查询:
SELECT
DateDiff("d", [Invoice]![TxnDate],[ReceivePaymentLine]![TxnDate]) AS ActualPaymentDays,
IIF ([ActualPaymentDays] < 90, 0.10, IIF ([ActualPaymentDays] < 120, 0.09, IID ([ActualPaymentDays] , 365, 0.05, 0))) AS PayPerValue
FROM
ReceivePaymentLine
INNER JOIN
Invoice ON ReceivePaymentLine.AppliedToTxnTxnID = Invoice.TxnID
我制作“ActualPaymentDaysRate”表:
ActualPaymentDay1
PayPerValue1
ActualPaymentDay2
PayPerValue2
ActualPaymentDay3
PayPerValue3
我将上面的查询更改为此查询:
SELECT
DateDiff("d",[Invoice]![TxnDate],[ReceivePaymentLine]![TxnDate]) AS ActualPaymentDays,
IIF ([ActualPaymentDays] < [ActualPaymentDaysRate.ActualPaymentDay1],[ActualPaymentDaysRate.PayPerValue1], IIF ([ActualPaymentDays] < [ActualPaymentDaysRate.ActualPaymentDay2], [ActualPaymentDaysRate.PayPerValue2], IIF ([ActualPaymentDays] < [ActualPaymentDaysRate.ActualPaymentDay3],[ActualPaymentDaysRate.PayPerValue3], 0))) AS PayPerValue
FROM
ActualPaymentDaysRate, ReceivePaymentLine
INNER JOIN
Invoice ON ReceivePaymentLine.AppliedToTxnTxnID = Invoice.TxnID
显示错误“不支持JOIN表达式”。
答案 0 :(得分:1)
你不能混合使用旧样式和新样式连接语法。
添加另一个联接:
SELECT DateDiff("d",[Invoice]![TxnDate],[ReceivePaymentLine]![TxnDate]) AS ActualPaymentDays, IIF ([ActualPaymentDays] < [ActualPaymentDaysRate.ActualPaymentDay1],[ActualPaymentDaysRate.PayPerValue1],IIF ([ActualPaymentDays] < [ActualPaymentDaysRate.ActualPaymentDay2],[ActualPaymentDaysRate.PayPerValue2], IIF ([ActualPaymentDays] < [ActualPaymentDaysRate.ActualPaymentDay3],[ActualPaymentDaysRate.PayPerValue3], 0))) AS PayPerValue
FROM ReceivePaymentLine
INNER JOIN Invoice ON ReceivePaymentLine.AppliedToTxnTxnID = Invoice.TxnID
JOIN ActualPaymentDaysRate ON {some condition}
此外,您在查询中将JOIN拼写为“JON”。我纠正了这个。
答案 1 :(得分:1)
你做错了是使用 ANSI SQL-89 语法和 ANSI SQL-92 JOIN语法
INNER JOIN
的旧语法 ANSI SQL-89 ,您可以在其中指定由您在查询中使用逗号分隔的两个表名称,如下所示
SELECT <column list>
FROM ActualPaymentDaysRate, ReceivePaymentLine
ANSI SQL-92 语法,您使用JOIN
关键字并使用您已完成的ON
指定条件
INNER JOIN Invoice ON ReceivePaymentLine.AppliedToTxnTxnID = Invoice.TxnID
但是你不能在同一个查询中同时使用它们。
在您的查询中,您有三个表,因此使用三个INNER JOIN
链接表。
如果忘记加入条件,不建议使用ANSI SQL-89语法,则不建议生成错误,而是在返回所有行的表之间应用笛卡尔积。
SELECT <column list>
FROM ActualPaymentDaysRate, ReceivePaymentLine
-- WHERE <condition> excluded , NOT a INNER JOIN anymore but still no error
但如果您忘记了SQL-92语法中的条件,则会立即生成错误。
答案 2 :(得分:0)
您的问题是您在内连接中指定了两个表名,需要两个内连接才能连接3个表。
看到这一点。
SELECT DateDiff("d",[Invoice]![TxnDate],[ReceivePaymentLine]![TxnDate]) AS ActualPaymentDays,
IIF ([ActualPaymentDays] < [ActualPaymentDaysRate.ActualPaymentDay1],[ActualPaymentDaysRate.PayPerValue1],
IIF ([ActualPaymentDays] < [ActualPaymentDaysRate.ActualPaymentDay2],[ActualPaymentDaysRate.PayPerValue2],
IIF ([ActualPaymentDays] < [ActualPaymentDaysRate.ActualPaymentDay3],[ActualPaymentDaysRate.PayPerValue3], 0))) AS PayPerValue
FROM ActualPaymentDaysRate INNER JOIN ReceivePaymentLine
ON <Match Condition>
INNER JOIN Invoice
ON ReceivePaymentLine.AppliedToTxnTxnID = Invoice.TxnID