[英]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.我收到了这个烦人的错误,但问题是我没有在查询中使用任何 JOIN 操作。 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.假设您的代码段来自
OPENROWSET
查询,您正在合并数据源,您试图在 Excel 连接中引用 SQL Server 表。 When connecting to an Excel workbook as a data source, you can only reference Excel worksheets, not SQL Server tables.连接到 Excel 工作簿作为数据源时,您只能引用 Excel 工作表,而不能引用 SQL Server 表。
Therefore, this source is not recognizable: [TradeCloud].[dbo].[Adminlist]
(correcting the opening parenthesis with square bracket).因此,无法识别此来源:
[TradeCloud].[dbo].[Adminlist]
(用方括号更正[TradeCloud].[dbo].[Adminlist]
括号)。 Instead, connect to an actual Excel worksheet within the workbook connection, placing the named reference outside of the connection string.相反,连接到工作簿连接内的实际 Excel 工作表,将命名引用置于连接字符串之外。 Below query (after you adjust mySheet should work to retrieve Excel-only data):
下面的查询(在您调整mySheet 后应该可以检索仅限 Excel 的数据):
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?也许 Excel 已连接到
[TradeCloud].[dbo].[Adminlist]
表? 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).如果是这样,您需要与数据库和架构建立单独的直接连接以访问表(绕过 Excel,它只是另一个客户端连接)。
Maybe you meant to populate an existing SQL Server table?也许您打算填充现有的 SQL Server 表? If so, run the needed append or create-table command then browse its contents:
如果是这样,请运行所需的 append 或 create-table 命令,然后浏览其内容:
-- 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?也许您正在尝试填充 Excel 工作簿? 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.如果是这样,请注意,这些命令(
OPENROWSET
和OPENDATASOURCE
)不会填充现有的 Excel 工作簿,而只是连接到外部源(Excel、Access 或其他数据源)作为检索数据的后端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.