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,
Ah yes! You have finally showed me how to keep this set permanently. I always did it via Query/Query Options/Results/Grid but every time I exited and entered SSMS this setting would go away.
LikeLike
@dishdy: It’s great to know that this post helped in making your day-to-day work simpler. Keep the feedback coming, and thank-you very much for reading!
LikeLike
Thank you for the great post.
LikeLike
Thank you for the informative post.
LikeLike