Connecting Tech Pros Worldwide Forums | Help | Site Map

Query to produce column names at top of results?

Newbie
 
Join Date: Aug 2007
Posts: 4
#1: Oct 18 '07
Hello,
We're using SQL Server 2000 and Query Manager (not Visual Studio). When your query results are returned, the column names are displayed at the top, but this information is NOT available for cut/paste to Excel. One of the workarounds we thought of was to return the column names within the query itself, and thought there was perhaps an option or other feature of SQL Server that would allow us to put the column headings into Excel without having the type in the column names. Ideas/suggestions are appreciated.
Thanks

Jim Doherty's Avatar
Moderator
 
Join Date: Aug 2007
Location: Derbyshire,England
Posts: 639
#2: Oct 19 '07

re: Query to produce column names at top of results?


Quote:

Originally Posted by bugs2bugs

Hello,
We're using SQL Server 2000 and Query Manager (not Visual Studio). When your query results are returned, the column names are displayed at the top, but this information is NOT available for cut/paste to Excel. One of the workarounds we thought of was to return the column names within the query itself, and thought there was perhaps an option or other feature of SQL Server that would allow us to put the column headings into Excel without having the type in the column names. Ideas/suggestions are appreciated.
Thanks

Heres one to add to your arsenal, adjust to suit you

Expand|Select|Wrap|Line Numbers
  1.  CREATE PROCEDURE dbo.usp_MakeSpreadsheet AS 
  2. exec sp_makewebtask @outputfile = 'c:\myspreadsheet.xls', 
  3.     @query = 'Select * from dbo.MyTable',
  4.     @colheaders =1, 
  5. @FixedFont=0,@lastupdated=0,@resultstitle='Here are the results',
  6.     @dbname ='NameOfYourDatabase'
  7. GO
  8.  
Regards

Jim :)
Reply