Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

excel

vba

adodb

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

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

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:

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]"

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?

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

like image 824
pablete Avatar asked Jan 15 '23 15:01

pablete


1 Answers

Access Jet/ADODB/ACE likes brackets with multiple tables

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]

like image 80
SeanC Avatar answered Jan 22 '23 19:01

SeanC