我正在使用 SQL Server 2008 并尝试导出到 Excel。我已经使用导出向导成功完成了这项工作,但是我正在尝试使用可执行查询来完成这项工作。这是我尝试使用的代码:
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
USE [RolandTest]
INSERT INTO OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=c:\Users\Roland\Desktop\ExcelExportsPractice\EEPractice.xlsx;','Select * from [GasEUR$]')
SELECT rcl.CaseCaseId AS CaseId, cc.Label AS CaseName, cc.Field, cc.Reservoir, cc.County, cc.State, cc.OperatorName, cc.BaseApiCode, cc.Location, cc.CaseType,
rcat.Label AS Category, rclass.Label AS Class, ps.ReportDate, cs.CaseDiscountFactor, corp.Label AS Scenario, cct.Label AS CorpCaseType, cp.Label AS MajorPhase,
rcl.SortId, ProjProject.Label AS Project
FROM PhdRpt.ReportCaseList_465 AS rcl INNER JOIN
CaseCases AS cc ON rcl.CaseCaseId = cc.CaseCaseId INNER JOIN
Corp.RsvCategory AS rcat ON cc.RsvCatSortNumber = rcat.RsvCatSortNumber INNER JOIN
Corp.RsvClass AS rclass ON cc.RsvClassSortNumber = rclass.RsvClassSortNumber INNER JOIN
CaseScenario AS cs ON cc.CaseCaseId = cs.CaseCaseId AND cc.CaseCaseId = cs.CaseCaseId AND cc.CaseCaseId = cs.CaseCaseId AND
cc.CaseCaseId = cs.CaseCaseId INNER JOIN
ProjectScenario AS ps ON cs.ProjProjectId = ps.ProjProjectId AND cs.CorpScenarioId = ps.CorpScenarioId AND cs.ProjProjectId = ps.ProjProjectId AND
cs.CorpScenarioId = ps.CorpScenarioId AND cs.ProjProjectId = ps.ProjProjectId AND cs.CorpScenarioId = ps.CorpScenarioId AND
cs.ProjProjectId = ps.ProjProjectId AND cs.CorpScenarioId = ps.CorpScenarioId AND cs.ProjProjectId = ps.ProjProjectId AND
cs.CorpScenarioId = ps.CorpScenarioId AND cs.ProjProjectId = ps.ProjProjectId AND cs.CorpScenarioId = ps.CorpScenarioId INNER JOIN
CorpScenario AS corp ON ps.CorpScenarioId = corp.CorpScenarioId INNER JOIN
CorpCaseType AS cct ON cc.CaseType = cct.CorpCaseTypeId INNER JOIN
ModelPhaseConfiguration AS mpc ON cs.ModelPhaseConfigurationId = mpc.ModelPhaseConfigurationId INNER JOIN
CorpProduct AS cp ON mpc.MajorPhaseId = cp.CorpProductId INNER JOIN
ProjProject ON ps.ProjProjectId = ProjProject.ProjProjectId
WHERE (cs.CorpScenarioId = 1) AND (cs.Deleted = 0)
GROUP BY rcl.CaseCaseId, cc.Label, cc.Field, cc.Reservoir, cc.County, cc.State, cc.OperatorName, cc.BaseApiCode, cc.Location, cc.CaseType, rcat.Label, rclass.Label,
ps.ReportDate, cs.CaseDiscountFactor, corp.Label, cct.Label, cp.Label, rcl.SortId, ProjProject.Label
ORDER BY rcl.SortId, CaseId
当我尝试执行此操作时,出现以下错误:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" returned message "Unspecified error".
Msg 7303, Level 16, State 1, Line 3
Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".
如果我以错误的方式接近这个,有人可以告诉我吗?任何建议或意见表示赞赏。谢谢您的帮助。