在Visual Studio中复制列标题和查询结果

RSW*_*RSW 7 sql sql-server visual-studio-2010 visual-studio visual-studio-2012

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:

在此输入图像描述

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:

在此输入图像描述

...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:

在此输入图像描述

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:

在此输入图像描述

...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?

(供参考,我使用的是Visual Studio 2012 Premium Update 3和Visual Studio 2010 Premium SP1Rel,后端使用SQL Server 2008)

Chr*_*ert 2

我正在运行 Visual Studio Ultimate 2012。当我选择SQL > Transact-Sql 编辑器 > 新查询时,我会得到一个新的查询框,就像您一样。但是,当我右键单击结果网格左上角的空单元格时,我确实可以选择使用标题进行复制。

所有这些都通过您安装在 PC 上的SQL Server Data Tools包运行。我的版本是11.1.30914.0。也许您需要数据工具的更新版本。如果您转到“帮助”>“关于”,您可以找到已安装的工具的版本。检查此页面以获取SQL Server Data Tools包。