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.
当我从Visual Studio中运行SQL Server查询时,我有时需要将查询结果复制到剪贴板以粘贴到另一个文档中。当我这样做时,我还想复制列标题(列名称)以及查询结果,以便粘贴数据。我一直能够使用SQL Server Management Studio(SSMS)执行此操作,但我无法弄清楚如何在Visual Studio中执行此操作。重新键入粘贴文档中的列标题非常耗时且烦人,即使SSMS提供了这种“复制列标题”功能,我也很少使用SSMS,除非我在TEST / PROD框中。在我的开发盒上,我住在Visual Studio中。
So for example, say I run the following query from within Visual Studio:
例如,假设我在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:
在SSMS中,右键单击结果网格最左上角的空灰色单元格时,“复制”选项右下方会出现“带标题复制”选项:
...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:
...但是当您在Visual Studio中右键单击结果网格的最左上角时,它似乎没有那个选项:
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:
从我读过的东西中,我确信在工具>选项> SQL Server工具> Transact-SQL编辑器>查询结果>结果到网格菜单中复制或保存结果选项时包含列标题可以解决这个问题:
...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.
...但是,即使在重新启动Visual Studio的所有打开实例后,它仍然无效。查询结果中的所有数据都会被正确复制和粘贴,但列标题不会被拾取。
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中的查询结果一起复制到剪贴板,以便它们都可以粘贴到另一个文档中?
(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)
(供参考,我使用的是Visual Studio 2012 Premium Update 3和Visual Studio 2010 Premium SP1Rel,后端使用SQL Server 2008)
1 个解决方案
#1
2
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.
我正在运行Visual Studio Ultimate 2012.当我选择SQL> Transact-Sql Editor> New Query时,我会像你一样得到一个新的查询框。但是当我右键单击结果网格左上角的空单元格时,我确实可以选择使用标题进行复制。
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.
所有这些都运行在PC上安装的SQL Server数据工具包中。我有版本11.1.30914.0。也许您需要更新版本的数据工具。如果您转到“帮助”>“关于”,则可以找到已安装的工具的版本。检查此页面以获取SQL Server数据工具包。
#1
2
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.
我正在运行Visual Studio Ultimate 2012.当我选择SQL> Transact-Sql Editor> New Query时,我会像你一样得到一个新的查询框。但是当我右键单击结果网格左上角的空单元格时,我确实可以选择使用标题进行复制。
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.
所有这些都运行在PC上安装的SQL Server数据工具包中。我有版本11.1.30914.0。也许您需要更新版本的数据工具。如果您转到“帮助”>“关于”,则可以找到已安装的工具的版本。检查此页面以获取SQL Server数据工具包。