Bryan Ulfers
Bryan Ulfers

Reputation: 125

How do I fix syntax error in JOIN statement while using SQL to query Excel spreadsheet?

I have an Excel workbook that contains several spreadsheets. I need to pull data from them using Jet SQL for a desktop application. I can query individual tables without a problem, but when I try to use a statement that requires a join, it gives me a generic Syntax Error in the JOIN statement. The query I'm having trouble with is:

SELECT      [Subscribed Email IDs].PIN
        ,   [Subscribed Email IDs].[Email Id]
        ,   [SubscriptionList].[Dealer Account]
        ,   [SubscriptionList].[Dealer Name] 
FROM        [Subscribed Email IDs$B4:C30000] 
INNER JOIN  [SubscriptionList$B4:J30000] 
ON          [Subscribed Email IDs].[PIN]        = [SubscriptionList].[Pin Txt] 
WHERE       [Subscribed Email IDs].[Email Id]   = '<email address value here...>'

I have to use ranges, because the spreadsheet has extra rows at the top that do not contain either headers or data, and the 'A' column contains nothing. I have tried without the ranges, and I get the same error, so I think it is something more basic with the way I have written the query. What am I missing?

Upvotes: 2

Views: 423

Answers (1)

onedaywhen
onedaywhen

Reputation: 57023

You are using a different range variable in your ON clause:

 ... FROM [Subscribed Email IDs$B4:C30000]
 ... ON [Subscribed Email IDs].[PIN] 

I suggest you use shorter range variables e.g. T:

 ... FROM [Subscribed Email IDs$B4:C30000] AS T
 ... ON T.[PIN] 

Upvotes: 2

Related Questions