0

我是使用 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 表达式”。

4

3 回答 3

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”。我在这个中纠正了这一点。

于 2013-05-05T06:34:16.973 回答
1

您做错的是同时使用ANSI SQL-89语法和ANSI SQL-92语法进行 JOIN

ANSI SQL-89的旧语法INNER JOIN是在其中指定用逗号分隔的两个表名,您在查询中执行这样的操作

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 语法中的条件,就会立即产生错误。

于 2013-05-05T06:45:18.093 回答
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
于 2013-05-05T06:49:35.677 回答