将存储过程的结果导出到Excel

时间:2013-09-16 21:06:49

标签: sql sql-server excel sql-server-2008 stored-procedures

我正在使用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)".

如果我接近错误的方式,有人可以告诉我吗?任何建议或意见表示赞赏。谢谢你的帮助。

0 个答案:

没有答案