Saving results with headers in Sql Server Management Studio

dublintech picture dublintech · May 20, 2012 · Viewed 203.9k times · Source

I am using SQL Server Management Studio.

I wish to save the results of a query to an excel file.

I choose "save as" and then save to CSV file which I can open in excel. All good except I am missing column headers, any ideas how I get them exported?

Answer

Diego picture Diego · May 20, 2012

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