As part of my work, I often need to copy-paste the results of a query into an Excel sheet for multiple reasons. The purpose of such a requirement could be as simple as having a record of what the data looked like before and after a change I made (as in when doing data cleanup or custom data modification work) to as complex as running an ad-hoc data analysis. Almost all of my production-grade queries use aliases and it would be the same aliases that I would prefer to have as column headers on the Excel sheets for sake of consistency. The easiest way to achieve this is to copy the headers along-with the data from the results tab of the SSMS window.
Traditionally, I would choose the option “Copy with Headers” popup-menu option (or use the equivalent Ctrl+Alt+C keyboard shortcut):
However, our memories do fail us sometimes and remembering to use “Copy with Headers” and not the plain “Copy” is error-prone. Hence, I have the following setting turned on in my SSMS options:
Re-launching the SSMS and attempting to copy (just plain copy) the result set also copies over the column headers to the applications of my choice, including Excel.
So, here are my questions – Do you use this built-in feature of the SSMS? Do you have any others to share with the group?
Until we meet next time,