save contents of a simple query to excel?

  • How can I run a simple 'Select *' query and save the results to a file in order to send it to someone!!!!!!!!!!!!!!!!!

  • Open Query Analyzer, enter your query, either choose "Results in Text" from the Query Menu or press CTRL-T, run your query, left click within the results pane, choose "Save As" from the File menu. Specify a name and save it.

    Alternatively, after getting the text results you could just set the focus to the results pane, press CTRL-A to select all, then CTRL-C to copy it and then paste it wherever you want it to go.

     

  • Another option is to export the table content. From EM right click on any table (doesn't matter), choose "export data" within "All Tasks". Follow the guide. You can choose a text file as output. You can modify the select query to suite your needs. You WILL have to choose the source table no matter which table you right clicked on. You can even run transformations as well if you needed to. If tying to get to excel this is probably your better bet.

  • When I cut and paste I loose all my formatting and when I paste it into excel it truncates characters!!!

  • Export it as described in my second post and import it into Excel.

  • Thank you, the export/import was exactly what I was looking for!

  • Another thing to try is to set the output to be Tab delimited (Tools | Options | Results) and then set "Default results to target:" to be "Results to Text" and then set "Results output format" to be "tab aligned".  When you run the query, click within the results pane and do a "File | Save As..."  This will let you save the file to disk, rename it to have an .CSV extension and then open in Excel.  Excel recognizes the tabs as delimiters and puts everything in it's own cell.

    Little more work than the export, but it works all the same.

    Ad maiorem Dei gloriam

  • You can cut & paste from Query Analyzer in grid mode, but you lose the column headings.

    You can cut & paste from QA in text mode/column aligned, but you have to go through "Text to Columns" (Data menu) in Excel to handle it.  This requires no setup, but you have to verify that Excel correctly sized all the columns.  Sometimes it gets confused, like with datetime columns it wants to separate the date and time.

    The text mode/tab delimited method works perfectly when pasted into Excel.  It's my favorite, but it's annoying when you forget to change it back to column aligned.

    Another method not mentioned yet is to run the query directly from Excel using Data - Import External Data - New Database Query.  This requires setting up an ODBC data source, and the SQL building tools in Excel are more primitive, but it has the advantage of remembering the query so you can just tell it to refresh the data to get a new copy.  The column headings are included, and are automatically formatted in boldface.  If you send someone else the spreadsheet the Refresh function won't work unless they create an identical ODBC data source.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply