views:

83

answers:

2

Is there a way to copy View output column headers along with the data? There is a setting in Options to include column headers with query results, but that only works with "New Query" and Stored Procedure output.

Looks like SSMS 2008 has this functionality built in to the contextual menu when you right click on results, but I only have 2005.

Am I out of luck?

Thanks for any help.

A: 

Tools, Options, Query Results, SQL Server, Results to Grid. There's an option in there for it.

Rob Farley
That's the option I was referencing in my question. It doesn't work for View output results.
DonnMt
It does - but it won't change the setting on queries you already have open. If you hit Ctrl-N and run your query in a new pane, it'll work.
Rob Farley
I don't have any queries open. I have pre-built views. With this setting turned on, I open a view, copy all data, and paste. No column headers. Works perfect for queries, stored procedures, but not saved views.
DonnMt
When you say "Open a view", how are you doing this? Hopefully you're saying "Script as Select to new window".
Rob Farley
A: 

It works if you SELECT * FROM VIEW_NAME in a regular query window. If you Open a view like you Open a table to show data, it won't copy the columns - that's a different, editable grid.

Cade Roux
Thanks. Should I be using Select to look at views anyway? I've always just used "Open View". I mostly use stored procedures, but for some quick data, I like a few views.
DonnMt
The editable grid (if you are using an updatable view it's editable) probably has some overhead with the cursor to be able to update appropriate rows. Typically I never use that for views and rarely for tables (only my configuration tables even have UPDATE/DELETE access). But my views are usually not possible to open that easily anyway, since they need to have some criteria added in order to return any reasonably manageable number of rows. In my data warehousing situation, the view on the smallest model would contain several million rows.
Cade Roux