2016-09-19 2 views
1

ich vier Tabellen zu verbinden versuchen, und ich erhalte die Fehlermeldung ‚Syntaxfehler in Ausdruck Join‘MS Access 2007 SQL-Syntax-Fehler in Join-Ausdruck

finden Sie unterhalb der Abfrage, die ich derzeit versuche

zu schreiben
SELECT a.*, 
switch(a.[Start Date] between b.[SEASON1START] and b.[SEASON1END],b.[LRA_S1_RT1_SGL], 
a.[Start Date] between c.[SEASON1START] and c.[SEASON1END],c.[LRA_S1_RT1_SGL], 
a.[Start Date] between d.[SEASON1START] and d.[SEASON1END],d.[LRA_S1_RT1_SGL]) as [Negotiated Rate Local], 
switch(a.[Start Date] between b.[SEASON1START] and b.[SEASON1END], 
b.[RATE_CURR],a.[Start Date] between c.[SEASON1START] and c.[SEASON1END],c.[RATE_CURR], 
a.[Start Date] between d.[SEASON1START] and d.[SEASON1END],d.[RATE_CURR]) as [Negotiated Currency] 
FROM ((([Q1001 - Split Transactions] a 
left join [2014 Negotiated Rate] b on (a.[RX_ID] = b.[PROPCODE] And YEAR(a.[Start Date] = 2014)) 
left join [2015 Negotiated Rate] c on (a.[RX_ID] = c.[PROPCODE] And YEAR(a.[Start Date] = 2015)) 
left join [2016 Negotiated Rate] d on (a.[RX_ID] = d.[PROPCODE] And YEAR(a.[Start Date] = 2016)) ; 

Antwort

2

MS Access erlaubt keine Konstanten in der on Klausel. Die Lösung? Wechseln Sie zu einer besseren Datenbank. Oh, Moment mal. Das ist nicht immer eine Option. Unterabfragen zur Rettung:

FROM ((([Q1001 - Split Transactions] a left join 
     (SELECT b.*, 2014 as yyyy FROM [2014 Negotiated Rate] as b 
     ) as b 
     on a.[RX_ID] = b.[PROPCODE] And YEAR(a.[Start Date]) = b.yyyy 
     ) left join 
     (SELECT c.*, 2015 as yyyy FROM [2015 Negotiated Rate] as c 
     ) as c 
     on a.[RX_ID] = c.[PROPCODE] And YEAR(a.[Start Date]) = c.yyyy 
    ) left join 
     (SELECT d.*, 2016 as yyyy FROM [2016 Negotiated Rate] as d 
    ) as d 
     on a.[RX_ID] = d.[PROPCODE] And YEAR(a.[Start Date]) = d.yyyy 
    ) 
+0

Danke für die Antwort, aber ich bekomme immer noch den gleichen Fehler, auch nach dem Ersetzen des Codes nach Ihrem Vorschlag. –

+0

"Wechseln zu einer besseren Datenbank" zu ehrlich :) – onedaywhen

+0

@AyanMukherje. . . Ich dachte, eine Unterabfrage würde es tun. Vielleicht ist eine Sicht erforderlich. –

1

Ihre ursprüngliche Abfrage sollte funktionieren. In MS Access können Sie Ausdrücke in ON Klauseln wie WHERE Klauseln haben (obwohl komplizierte Ausdrücke nicht sichtbar in Design View nur in SQL View).

Insbesondere umhüllen Sie die YEAR() Funktion nicht ordnungsgemäß. Berücksichtigen Sie die folgende Einstellung:

FROM ((([Q1001 - Split Transactions] a 
left join [2014 Negotiated Rate] b 
     on (a.[RX_ID] = b.[PROPCODE] And YEAR(a.[Start Date]) = 2014)) 
left join [2015 Negotiated Rate] c 
     on (a.[RX_ID] = c.[PROPCODE] And YEAR(a.[Start Date]) = 2015)) 
left join [2016 Negotiated Rate] d 
     on (a.[RX_ID] = d.[PROPCODE] And YEAR(a.[Start Date]) = 2016));