2015-11-27 94 views
0

我知道在這裏處理不支持的連接表達式時存在一堆問題,我找不到指向我的情況的問題。訪問SQL JOIN表達式不支持

我的查詢看起來是這樣的:

SELECT T1.*, T2.Year, T3.Force, T4.Group AS myGroup 
FROM ((AllQuestions AS T1 
INNER JOIN Years AS T2 ON T1.ID_Year = T2.ID) 
INNER JOIN Forces AS T3 ON T1.Questions_Force = T3.ID) 
INNER JOIN Groups AS T4 ON T4.ID = " & (Me.Texte423) & " 
ORDER BY Categories, T1.Questions; 

正如你可以在網上指的T4,我想匹配表族的ID在報告中從匹配的文本框的值看(它可能很重要)。

我收到的錯誤看起來像:不支持JOIN表達式。 「看起來」,因爲我使用法語版的Access,所以它是一個基本的翻譯...

我在做什麼錯誤請?

+0

什麼錯誤信息你好嗎?這總能幫助我們。 – nicomp

+0

MS Access不允許在連接條件中使用常量。 – Arvo

回答

2

我想你會需要CROSS JOIN表Groups,然後將T4.ID查詢的WHERE子句中,但這並不解決可能T4.ID和正在使用加入其他ID列之間存在的關係其他表:

SELECT T1.*, T2.Year, T3.Force, T4.Group AS myGroup 
FROM ((AllQuestions AS T1 
INNER JOIN Years AS T2 ON T1.ID_Year = T2.ID) 
INNER JOIN Forces AS T3 ON T1.Questions_Force = T3.ID) 
CROSS JOIN Groups AS T4 
WHERE T4.ID = " & (Me.Texte423) & " 
ORDER BY Categories, T1.Questions; 

如果有團體和ID AllQuestions之間的關係,那麼你需要繼續沿着這條修改查詢:

SELECT T1.*, T2.Year, T3.Force, T4.Group AS myGroup 
FROM ((AllQuestions AS T1 
INNER JOIN Years AS T2 ON T1.ID_Year = T2.ID) 
INNER JOIN Forces AS T3 ON T1.Questions_Force = T3.ID) 
INNER JOIN Groups AS T4 ON T1.{Group ID Relation} = T4.ID 
WHERE T4.ID = " & (Me.Texte423) & " 
ORDER BY Categories, T1.Questions; 
+0

Thx爲您的答案,我真的從來沒有使用交叉連接,但它可能是有道理的...我嘗試了第一個解決方案,因爲我不想使用組和AllQuestions之間的關係,但執行時出現此錯誤:語法錯誤在where子句中,並且CROSS字突出顯示... –

+1

這是解決方案,只有Access沒有'CROSS JOIN'關鍵字。取而代之,只需在FROM列表中使用逗號','。 – Andre

0

你不能那樣做。但是你可以修改查詢的SQL。其設置爲:

SELECT T1.*, T2.Year, T3.Force, T4.Group AS myGroup 
FROM ((AllQuestions AS T1 
INNER JOIN Years AS T2 ON T1.ID_Year = T2.ID) 
INNER JOIN Forces AS T3 ON T1.Questions_Force = T3.ID) 
INNER JOIN Groups AS T4 ON T4.ID = {0} 
ORDER BY Categories, T1.Questions; 

然後設置/修改SQL當你需要它:

MyQdy.SQL = Replace(SQL, "{0}", Me!Texte423.Value) 
+0

我試過了,我得到一個錯誤:這個GUID的格式不正確:「T4.ID = {0」。 –

+0

當然,您需要在運行SQL之前運行替換。 – Gustav