title: Export the Result of a Stored Procedure to Excel
body: <p>I am using SQL Server 2008 and trying to export to Excel. I have successfully done this using the export wizard however I am trying to do this using an executable query. Here is the code that I am trying to use:</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>When I try to execute this I get the following errors:</p>
  
  <p><code>OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" returned message "Unspecified error".</code></p>
  
  <p><code>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)".</code></p>
  
  <p>Can someone please let me know if I am approaching this the wrong way? Any suggestions or comments are appreciated. Thank you for your help.</p>