locked
SQL Server 2012: Import and Export Wizard - Exporting Multiple Result Sets at Once? RRS feed

  • Question

  • I'm working in SQL Server 2012 trying to export some data from our database into an Excel file. My SQL statement has two separate Select statements. They are not joined by a union. When I Execute them inside of SQL Server Management Studio, with Results set to go to a Grid, I get two result sets back. Two full tables of data.

    However, when I use the Import and Export Wizard, the Excel sheet only has the first set of data. What do I need to do to have it so both result sets show up in the excel file?

    Tuesday, March 3, 2015 4:24 PM

Answers

  • If you provide 2 queries, SSIS will consider only first provided query and export result to excel.

    1) You may run the query manually in SSMS and copy paste the result set to excel by yourself.

    2) You may export the data twice to 2 excel sheets

    3) You may also create SSIS package which will extract the data from SQL and load to Excel sheet1 and sheet2 but this one is time consuming.


    -Vaibhav Chaudhari

    • Marked as answer by CRLinc Thursday, April 2, 2015 2:07 PM
    Tuesday, March 3, 2015 5:40 PM

All replies

  • If you provide 2 queries, SSIS will consider only first provided query and export result to excel.

    1) You may run the query manually in SSMS and copy paste the result set to excel by yourself.

    2) You may export the data twice to 2 excel sheets

    3) You may also create SSIS package which will extract the data from SQL and load to Excel sheet1 and sheet2 but this one is time consuming.


    -Vaibhav Chaudhari

    • Marked as answer by CRLinc Thursday, April 2, 2015 2:07 PM
    Tuesday, March 3, 2015 5:40 PM
  • Why cant use merge them using union/union all if intention is to get them to same sheet? Is it like the metadata is different so that they cant be merged to single sheet?

    If that being the case you need to do it in two steps. 


    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    ----------------------------
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

    Tuesday, March 3, 2015 6:16 PM