2014-02-12 43 views
0

我有excel中插入的数据大数据,所有的数据都来自sql server,我想准备插入查询,它会一次插入一堆记录..如何插入数据,使用excel中的select

INSERT INTO [Sheet1$] (ID,Name) 
SELECT '1' AS ID,'XYZ' AS Name UNION 
SELECT '1' AS ID,'XYZ' AS Name UNION 
SELECT '1' AS ID,'XYZ' AS Name 

但它给我的错误,如

Query input must contain at least one table or query. 

回答

0

尝试使用此选项。

INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=D:\testing.xlsx;;HDR=YES;IMEX=1', 'SELECT Id, Name FROM [Sheet1$]') 
SELECT '1' AS ID,'XYZ' AS Name 
UNION ALL 
SELECT '1' AS ID,'XYZ' AS Name 
UNION ALL 
SELECT '1' AS ID,'XYZ' AS Name 

在这里,我假设你已经启用您的SQL Server的特设分布式查询选项。

+0

我已配置 执行sp_configure'show advanced options',1; RECONFIGURE; GO Exec sp_configure'Ad Hoc Distributed Queries',1; RECONFIGURE; GO EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0',N'AllowInProcess',1; GO EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0',N'DynamicParameters',1; GO 但仍然得到错误,如 消息7399,级别16,状态1,第3行 OLE DB提供程序 “Microsoft.ACE.OLEDB.12.0” 链接服务器 “(空)” 报告错误。提供者没有提供任何关于错误的信息。 –

+0

这里我使用** Microsoft.ACE.OLEDB.12.0 ** bcs我已经在我的系统中安装了Microsoft Office 2007。您可以尝试使用** Microsoft.Jet.OLEDB.4.0 **并让我知道... –

+0

我已经在我的系统上安装了Office 2010 64bit,所以OLEDB4​​.0不适用于我.. 我也安装了Microsoft Access Engine 64bit,我的系统是Win 7 64bit,而且我的SQL Server 2008是64bit –

相关问题