Saving results with headers in Sql Server Management Studio Saving results with headers in Sql Server Management Studio sql sql

Saving results with headers in Sql Server Management Studio


Tools > Options > Query Results > SQL Server > Results to Text (or Grid if you want) > Include columns headers in the result set

You might need to close and reopen SSMS after changing this option.

On the SQL Editor Toolbar you can select save to file without having to restart SSMS


Try the Export Wizard. In this example I select a whole table, but you can just as easily specify a query:

enter image description here

enter image description here

enter image description here

enter image description here

(you can also specify a query here)

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here


Another possibility is to use the clipboard to copy and paste the results directly into Excel. Just be careful with General type Excel columns, as they can sometimes have unpredictable results, depending on your data. CTL-A anywhere in the result grid, and then right-click:

enter image description here

If you have trouble with Excel's General format doing undesired conversions, select the blank columns in Excel before you paste and change the format to "text".