简体   繁体   中英

OLE DB provider “Microsoft.ACE.OLEDB.12.0” for linked server “(null)” returned message “Syntax error in JOIN operation.”

I am getting this annoying error, but the thing is that I do not use any JOIN operation in my query. Here is the snippet:

   ('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=C:\Users\tcmnoc\Desktop\Test.xlsx;','SELECT * FROM ([TradeCloud].[dbo].[Adminlist]')
   Select * from [TradeCloud].[dbo].[Adminlist]```

Assuming your snippet derives from an OPENROWSET query, you are conflating data sources where you attempt to reference an SQL Server table inside an Excel connection. When connecting to an Excel workbook as a data source, you can only reference Excel worksheets, not SQL Server tables.

Therefore, this source is not recognizable: [TradeCloud].[dbo].[Adminlist] (correcting the opening parenthesis with square bracket). Instead, connect to an actual Excel worksheet within the workbook connection, placing the named reference outside of the connection string. Below query (after you adjust mySheet should work to retrieve Excel-only data):

SELECT * 
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
                'Excel 12.0; Database=C:\Users\tcmnoc\Desktop\Test.xlsx;',
                [mySheet])

Without fuller context, I consider the following assumptions:

  • Maybe Excel is connected to the [TradeCloud].[dbo].[Adminlist] table? If so, you need to make a separate, direct connection to the database and schema to access the table (bypassing Excel which is just another client connection).

  • Maybe you meant to populate an existing SQL Server table? If so, run the needed append or create-table command then browse its contents:

     -- APPEND TO TABLE INSERT INTO [TradeCloud].[dbo].[Adminlist] (Col1, Col2, Col3, ...) SELECT xl.Col1, xl.Col2, xl.Col3, ... FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0; Database=C:\\Users\\tcmnoc\\Desktop\\Test.xlsx;', [mySheet]) xl; -- CREATE TABLE SELECT xl.Col1, xl.Col2, xl.Col3, ... INTO [TradeCloud].[dbo].[Adminlist] FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0; Database=C:\\Users\\tcmnoc\\Desktop\\Test.xlsx;', [mySheet]) xl; -- BROWSE CONTENTS SELECT * [TradeCloud].[dbo].[Adminlist];
  • Maybe you are attempting to populate an Excel workbook? If so, do note, these commands ( OPENROWSET and OPENDATASOURCE ) do not populate an existing Excel workbook but simply connects to external sources (Excel, Access, or other data sources) as a backend to retrieve data.

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