BLOGS BY TOPIC▼
BLOGS BY AUTHOR▼
BLOGS BY YEAR▼
While SQL Server Management Studio is a powerful tool for writing queries, it has absolutely no concessions towards making the results of those queries remotely presentable! This blog describes several techniques for getting the results of a query into another application so that you can format them to your heart’s content.
- Exporting Query Results in SQL Server (this blog)
- Saving or Copying the Results of a Query
- Using the Export Wizard in Management Studio
Posted by Andrew Gould on 04 February 2013
You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Exporting Query Results in SQL Server
SQL Server Management Studio is a great tool for writing queries to return a set of information from a database, but it's absolutely hopeless at formatting the results! If you need to tidy up the results of a query you'll need some way to extract or export them and this blog explains a few of the techniques you can use to do precisely that.
Changing the Output of a Query
Normally, when you execute a query in Management Studio the results appear in the grid at the bottom of the screen.
The grid is the standard view for displaying query results.
You can change the output of a query using a set of three buttons on the Edit SQL toolbar at the top of the screen.
The first three buttons shown in this screenshot allow you to change the output type of your query.
You can also change the output style of a query by right-clicking anywhere within your query and choosing the option shown in the diagram below:
Right-click within the query and choose Results To, followed by the output type that you want.
Once you've changed the output type you'll need to execute the query again in order to see the changes.
Sending Query Results to a File
If you choose Results to File from the list of query output types, the next time you run the query you'll be prompted to save a file which will contain the query results.
The default file type is Report files with an .rpt extension.
The files generated by this query output type are designed to be used with Crystal Reports for Microsoft Visual Studio.
This is the message you'll see if you attempt to open the file by double-clicking on its icon.
Of course, this type of output is only useful if you're using Crystal Reports to format your query results! What if you wanted to use a different tool, such as Microsoft Excel, to create reports? Read the next part of this series to find out!