2015-09-18 80 views
0

我正在嘗試使用JET連接查詢Excel工作簿中的幾個命名範圍,並且收到錯誤(運行時錯誤'-2147217900(80040e14)':連接表達式不是支持)當我嘗試添加第二個條件的加入一個:錯誤:「不支持連接表達式」

Dim strQuery As String 
strQuery = "SELECT mrx.Underlying " 
strQuery = strQuery & ",mrx.[exp] " 
strQuery = strQuery & ",sum(mrx.[codc]) " 
strQuery = strQuery & ",max(mapDt.[Str]) " 
strQuery = strQuery & "FROM ((([dataMRX] AS mrx " 

strQuery = strQuery & "LEFT OUTER JOIN [mapDt] AS mapDt on " 
strQuery = strQuery & "(mrx.[exp] = mapDt.[DtNumeric])) " 

strQuery = strQuery & "LEFT OUTER JOIN [mapUdl] AS mapUdl on " 
strQuery = strQuery & "(mrx.[Underlying] = mapUdl.[rmpUdl])) " 

strQuery = strQuery & "LEFT OUTER JOIN [dataTtm] AS ttm on " 
strQuery = strQuery & "(ttm.[Underlying] = mapUdl.[ttmUdl] " 
strQuery = strQuery & "AND ttm.[End Month] = mapDt.[Dt])) " 

strQuery = strQuery & "GROUP BY mrx.Underlying, mrx.[exp] " 
strQuery = strQuery & "ORDER BY mrx.Underlying DESC " 

特別是,如果我刪除第一或第二,在過去左外連接條件(ttm.[Underlying] = mapUdl.[ttmUdl]tmm.[End Month] = mapDt.[Dt])的查詢工作正常。但是,在這兩種情況下,我都會遇到錯誤。

我使用JET 4.0:

strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _ 
    & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";" 
+0

嘗試從「FROM」之前刪除括號中的一個,並從語句結尾刪除一個括號。 – Gareth

+0

thx爲響應,看起來像我得到了相同的連接錯誤 – ignorantcity

回答

1

我沒有絕對的把握,這是正確的,但它確實與Jet引擎執行。請試一試。

SELECT sub.Underlying ,sub.[exp] ,sum(sub.[codc]) ,max(sub.[Str]) 
FROM (
    SELECT mrx.underlying, mrx.exp, mrx.codc, mapDt.Dt, mapDt.str, mapUdl.ttmUdl 
    FROM ( 
     [dataMRX] AS mrx 
     LEFT OUTER JOIN [mapDt] AS mapDt on (mrx.[exp] = mapDt.[DtNumeric]) 
    ) 
    LEFT OUTER JOIN [mapUdl] AS mapUdl on (mrx.[Underlying] = mapUdl.[rmpUdl]) 
) as sub 
LEFT OUTER JOIN [dataTtm] AS ttm on ((ttm.[Underlying] = sub.[ttmUdl]) AND (ttm.[End Month] = sub.[Dt]))  

GROUP BY sub.Underlying, sub.[exp] 
ORDER BY sub.Underlying DESC 
+1

運作良好,謝謝! – ignorantcity

相關問題