Saving SQL Column Headers Results
Sometimes you can run into problems that tend to take up time and could have been solved in a minute. One of these strange problems is when you attempt to save a Microsoft SQL query result grid to a CSV file.
Using Microsoft SQL Server Management Studio (SSMS)
Now most of DBA or Developers tend to use the Microsoft SQL Server Management Studio (SSMS) to do the necessary general SQL work. As you expected when you execute a query the results grid appears displaying the results. I as countless others tend to copy the information and save it in an excel spreadsheet to do further analysis. But there are times you may need to save the information into a CSV file for the purpose of processing the information later or with a different application.
If you use the option to save out to a CSV file you will notice that the column headers are missing and you are pretty much baffled.
A simple click to solve the issue
It is not you but apparently Microsoft decided not to default a simple setting that saves the column headers in your CSV file. What you need to simply do is click on Tools – Options which will open the Options Dialog box.
In this Dialog box you will click on Query Results – Results to Grid. You will see the “Include column headers when copying or saving the results”, click to enable it. You should see the similar as the image below. Click OK to close the dialog and will have to restart the Server Management Studio application for the settings to take hold.
This is something we all take for granted and by diving into the vast amount of options you can solve it. So go ahead and take a look to see if you have it set or need to.