简体   繁体   中英

SQL - Join Expression Not Supported

I am new using Access and trying to change this query:

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

I make "ActualPaymentDaysRate" table:

ActualPaymentDay1
PayPerValue1
ActualPaymentDay2
PayPerValue2
ActualPaymentDay3
PayPerValue3

And I change the query above to be this query:

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

It shows error "JOIN expression not supported".

You can't mix-n-match old style and new style join syntax.

Add another join:

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}

Also, you spelled JOIN as "JON" in your query. I corrected that in this one.

What you are doing wrong is using both ANSI SQL-89 Syntax and ANSI SQL-92 Syntax for JOIN

The old syntax for INNER JOIN which is ANSI SQL-89 is in which you specify both table names seprated by comma which you done in your query like this

SELECT <column list>
FROM ActualPaymentDaysRate, ReceivePaymentLine 

The ANSI SQL-92 syntax is in which you use JOIN keyword and specify condition using ON which you have done like

 INNER JOIN Invoice ON ReceivePaymentLine.AppliedToTxnTxnID = Invoice.TxnID

BUT you cannot use them at same time in same query. In your query you have three tables and hence use three INNER JOIN to link the tables.

Using ANSI SQL-89 syntax is not recommended becuse if you forget about joining condition , no error is generated , instead a cartesian product is applied between the tables returning all the rows.

SELECT <column list>
FROM ActualPaymentDaysRate, ReceivePaymentLine 
--  WHERE <condition> excluded , NOT a INNER JOIN anymore but still no error

But if you forget condition in SQL-92 syntax , immediately error is generated.

Your problem is you've specified two table names in inner join, you need two inner join to join 3 tables.

See this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM