Background:
I have an Excel workbook which I am treating as a database.
I am using ADO reference library ("Microsoft ActiveX Data Objects Library")
I connect to the workbook with MSDASQL
My Connection string = "Provider=MSDASQL; Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; DBQ=****[insert fullname of excel workbook]****; ReadOnly=True; HDR=Yes;"
Problem:
Why can't I write SQL queries involving JOIN with MSDASQL? I try different variations but I get an error every time.
Below are examples of queries that have failed
(Please ignore the fact that SELECT is not returning anything from the other tables in the queries - I was trying to narrow down where the error was occurring)
- SELECT [tblSong$].* FROM ([tblSong$] LEFT OUTER JOIN [tblTitle$] ON [tblTitle$.ID] = [tblSong$.fkTitle]) WHERE [tblSong$.ID] = 100
- SELECT [tblSong$].* FROM ([tblSong$] OUTER JOIN [tblTitle$] ON [tblTitle$.ID] = [tblSong$.fkTitle]) WHERE [tblSong$.ID] = 32
- SELECT [tblSong$].* FROM ([tblSong$] LEFT JOIN [tblTitle$] ON [tblTitle$.ID] = [tblSong$.fkTitle]) WHERE [tblSong$.ID] = 32
- SELECT [tblSong$].* FROM [tblSong$] JOIN ([tblTitle$] ON [tblTitle$.ID] = [tblSong$.fkTitle]) WHERE [tblSong$.ID] = 32
- SELECT [tblSong$].* FROM [tblSong$] JOIN [tblTitle$] ON [tblTitle$.ID] = [tblSong$.fkTitle] WHERE [tblSong$.ID] = 32
- SELECT [tblSong$].* FROM [tblSong$] INNER JOIN ([tblTitle$] ON [tblTitle$.ID] = [tblSong$.fkTitle]) WHERE [tblSong$.ID] = 32
Finally after much frustration, I rewrote my queries to avoid any use of the word 'JOIN'
Guess what? The queries work now * (examples at bottom of post)
But I hate it. Because:
- It's forcing me to learn an unnatural SQL query structure (because I cant join, I have to move all the ON parts to the WHERE section) and
- as a result of the above - the query strings are 'bloated'
- I'm guessing that these sloppy queries will slow down the response times as the database grows
Can anyone please tell me how to properly write JOIN queries so that they run in MSDASQL?
* Below are some examples of how I wrote my queries while avoiding any use of the word 'JOIN'. Foul aren't they?
- SELECT [tblSong$].* FROM [tblSong$], [tblTitle$] WHERE [tblSong$.ID] = 32 AND [tblTitle$.ID]=[tblSong$.fkTitle]
- SELECT [tblSong$].*, [tblTitle$.Name] FROM [tblSong$], [tblTitle$] WHERE [tblSong$.ID] = 32 AND [tblTitle$.ID]=[tblSong$.fkTitle]
- SELECT [tblSong$].*, [tblTitle$.Name], [tblArtist$.Name] FROM [tblSong$], [tblTitle$], [tbjSongArtist$], [tblArtist$] WHERE [tblSong$.ID] = 100 AND [tblTitle$.ID]=[tblSong$.fkTitle] AND [tbjSongArtist$.fkSong] = 100 AND [tblArtist$.ID] = [tbjSongArtist$.fkArtist]
Bookmarks