在 VBA 过程中使用 ADODB 查询 Excel 文件时是否有多个 JOIN 不可用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12322576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 17:38:06  来源:igfitidea点击:

Are multiple JOINs unavailable when using ADODB to query an Excel file in a VBA procedure?

sqlexcel-vbaadodbvbaexcel

提问by pablete

I have 3 sheets with data formatted as tables. The sheets names are "Riesgos", "Eventos" and "EventosRiesgos".

我有 3 张数据格式为表格的工作表。工作表名称是“Riesgos”、“Eventos”和“EventosRiesgos”。

EventosRiesgo has information relating events and risks (many to many relationship).

EventosRiesgo 拥有与事件和风险(多对多关系)相关的信息。

I'm trying to get all the risks from Riesgos, but also the events related to the risks from (. I'm using ADODB to query the sheets as database tables and using the following SQL:

我试图从 Riesgos 中获取所有风险,但也从 (. 我正在使用 ADODB 将工作表作为数据库表查询并使用以下 SQL:

SELECT * FROM [Riesgos$] r
LEFT JOIN [EventosRiesgos$] er ON r.[Id]=er.[Id Riesgo]
LEFT JOIN [Eventos$] e ON er.[Id Evento]=e.[Id]

But i get an error, it's in Spanish but a rough translation would be: Syntax error (missing operator) in expression "r.[Id]=er.[Id Riesgo] LEFT JOIN [Eventos$] e ON er.[Id Evento]=e.[Id]"

但是我得到一个错误,它是西班牙语,但粗略的翻译是:表达式“r.[Id]=er.[Id Riesgo] LEFT JOIN [Eventos$] e ON er.[Id Evento]中的语法错误(缺少运算符) ]=e.[Id]"

When I run the query only using the first 2 lines (only one join) everything works as expected. My question is: Why is the query not working when I use the two JOINs?

当我只使用前两行(只有一个连接)运行查询时,一切都按预期工作。我的问题是:为什么当我使用两个 JOIN 时查询不起作用?

Can anyone help me, at least to find documentation on the use of ADODB to query Excel sheets?

任何人都可以帮助我,至少可以找到有关使用 ADODB 查询 Excel 表格的文档吗?

回答by SeanC

AccessJet/ADODB/ACE likes brackets with multiple tables

AccessJet/ADODB/ACE 喜欢多表的括号

SELECT  * FROM ( [Riesgos$] r
LEFT JOIN [EventosRiesgos$] er ON r.[Id]=er.[Id Riesgo] )
LEFT JOIN [Eventos$] e ON er.[Id Evento]=e.[Id]

The only difference is brackets around the [riesgos$] r .... er.[Id Riesggo]

唯一的区别是括号周围 [riesgos$] r .... er.[Id Riesggo]