简体   繁体   中英

Error: “Join expression not supported”

I'm attempting to query a few named ranges in an Excel workbook using a JET Connection and am receiving an error (Run-time error '-2147217900 (80040e14)': Join expression not supported) when I attempt to add a second condition the one of the joins:

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 "

Specifically, if I remove either the first or second join condition in the last left outer join (ttm.[Underlying] = mapUdl.[ttmUdl] or tmm.[End Month] = mapDt.[Dt]) the query works fine. However with both conditions present, I get an error.

I'm using JET 4.0:

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

I'm not absolutely sure this is correct, but it does execute with the Jet engine. Please give it a try.

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 

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