Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2012
    Posts
    188

    Unanswered: Export SQL Select Query Results To Excel

    I am running a SQL stored procedure which runs 3 queries on 3 different SQL tables. What is my best option to export the results of these 3 queries to excel?

    EDIT ---
    If it matters they are all SELECT queries, and at most will return < 500 rows.
    Last edited by jo15765; 10-12-12 at 20:12.

  2. #2
    Join Date
    Aug 2012
    Posts
    30
    You've several options


    1. SSIS Package
    2. OPENROWSET

    If you want to automate it you can configure a job to utilize above options.

    Do you want data to end up in same or different sheets?

  3. #3
    Join Date
    Feb 2012
    Posts
    188
    Ideally, I would have each different Select statement on it's own worksheet. Can you elaborate on how to do either of those options, please?

  4. #4
    Join Date
    Aug 2008
    Posts
    147
    Check Powershell , it is very useful with manipulating SQL Results into Excel worksheets.Here is an example of a script - which creates an SMO object and places results in Excel worksheet - Powershell sql server security audit - SQL Server DBA
    ---------------------------------
    www.sqlserver-dba.com
    www.dba-db2.com

  5. #5
    Join Date
    Feb 2012
    Posts
    188
    Quote Originally Posted by JackVamvas View Post
    Check Powershell , it is very useful with manipulating SQL Results into Excel worksheets.Here is an example of a script - which creates an SMO object and places results in Excel worksheet - Powershell sql server security audit - SQL Server DBA
    I looked at the link you provided and it didn't really look like it was exporting query results to Excel. I googled Powershell, and came across this:
    Write to Excel File With PowerShell

    But it also is not about exporting SQL Server Select queries to Excel.

  6. #6
    Join Date
    Aug 2008
    Posts
    147
    Both those links indicate a process whereby a connecttion is made to SQL Server , a recordset is generated - and exported to Excel - using a Powershell script.
    1)Are you looking for a way within the Stored Procedure to export to Excel?
    2)A SQL Server process , such as SSIS manages the process?
    3)Are you OK about a script framework outside of SQL Server manages the process?
    ---------------------------------
    www.sqlserver-dba.com
    www.dba-db2.com

  7. #7
    Join Date
    Feb 2012
    Posts
    188
    Quote Originally Posted by JackVamvas View Post
    Both those links indicate a process whereby a connecttion is made to SQL Server , a recordset is generated - and exported to Excel - using a Powershell script.
    1)Are you looking for a way within the Stored Procedure to export to Excel?
    2)A SQL Server process , such as SSIS manages the process?
    3)Are you OK about a script framework outside of SQL Server manages the process?
    I'll just answer your questions below
    1) That is my preferred method, if that is possible.
    2) I would preferr it to be a SQL Server method so that everything can be done in one place
    3) I have never run a script framework outside of SQL Server, so that is all foreign to me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •