Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying column headings along with query results in Visual Studio

When I run SQL Server queries from within Visual Studio, I sometimes need to copy the query results to the clipboard for pasting into another document. When I do this, I also want to copy the column headers (column names) along with the query results so that they get pasted with the data. I have always been able to do this with SQL Server Management Studio (SSMS), but I can't figure out how to do this in Visual Studio. It's quite time-consuming and annoying to re-type the column headings in the pasted document, and even though SSMS provides this "copy column headers" capability, I rarely use SSMS unless I'm on the TEST/PROD boxes. On my dev box I live inside Visual Studio.

So for example, say I run the following query from within Visual Studio:

enter image description here

In SSMS, when you right-click the empty gray cell in the upper-leftmost corner of the results grid, there is a "Copy with Headers" option right under the "Copy" option:

enter image description here

...but when you right-click the upper-leftmost corner of the results grid in Visual Studio, it doesn't seem to have that option there:

enter image description here

From things I had read, I thought for sure the Include column headers when copying or saving the results option on the Tools > Options > SQL Server Tools > Transact-SQL Editor > Query Results > Results To Grid menu would do the trick:

enter image description here

...but alas, even after restarting all open instances of Visual Studio, it still did not work. All the data from the query results does get copied and pasted properly, but the column headers do not get picked up.

So...is there any way to copy column headings to the clipboard along with the query results in Visual Studio so that they can both be pasted into another document?

(For reference, I'm using Visual Studio 2012 Premium Update 3 and Visual Studio 2010 Premium SP1Rel, with SQL Server 2008 on the back end)

like image 979
RSW Avatar asked Sep 21 '13 00:09

RSW


People also ask

How do I copy a header with Results in SQL Developer?

Once you have selected the results (Ctrl +A) then use Ctrl + Shift + C to copy, this will copy the headers aswell.

How do I copy column headers in SQL?

Select cells from the columns you want to copy (CTRL+Click), choose "Copy selected Headers" in Results grid context menu and column names will be copied to clipboard. This action creates a comma-separated list that can be pasted wherever you need.


1 Answers

I am running Visual Studio Ultimate 2012. When I choose SQL > Transact-Sql Editor > New Query I get a new query box just like you have. But when I right click the empty cell in the top left corner of the result grid I do get the option to copy with headers.

All of that runs off of the SQL Server Data Tools package that you have installed on your PC. I have version 11.1.30914.0. Maybe you need an updated version of the data tools. If you go to Help > About you can find the version of the tools you have installed. Check this page for the package SQL Server Data Tools.

like image 140
Chris Albert Avatar answered Nov 09 '22 12:11

Chris Albert