我在excel中插入数据大数据,所有数据都来自sql server,我想准备插入查询,这将一次插入一堆记录...
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 :(得分: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中启用了 Ad Hoc Distributed Queries 选项。