Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying headers from query analyzer

Status
Not open for further replies.

jorbroni

Technical User
Dec 5, 2002
24
0
0
US

When I run a query in query analyzer I would copy and paste the results into excel. The problem is that when I paste the results it doesn't paste the headers as well like MS access does. I was wondering if there was a way that I can copy and paste the field headers as well.

Thanks
 
Not that I've found yet - annoying isn't it!! ;-) --James
 
Why are you copying and pasting into Excel? There's a better way.

Before you run the script in QA, set the Options for the results to be Comma Separated Values (CSV).

Run the script using the save to file option and save as a .txt file.

Open MS Excel.

Choose Data > Get External Data > Import Text Data

Follow the wizard.

-SQLBill
 
The following will work:

Try this, rather than using query analyser, use Enterprise Manager

Right click on the database and select all tasks proceeded by export data
Specify your source as 'Microsoft OLE DB Provider for SQL Server' (Usually the default) and give the database you are copying from
Specify 'Excel 97-2000' as the destination and give the file a name and directory
Next tick 'Use a Query to specify data to transfer'
Then cut and paste your query from query analyser
Select run immediate and away it should go and create you an excel file with headers as per the results from query analyser

Damian
 
This is very annoying. However, if you have an ODBC connection to the DB, you can open Excel, go to Data, get external data, New Database Query. This will open a query builder similar to Access. (Occasionally, you will need the Office Install CD to finish this add-on) If your more comfortable with GUI building this is great, but if your like me and would rather type the query, you have the option. You can cut even write and test your QUERY from Query Analyzer and then paste it or simply re-type in MS Query (Excel). Then, when you are satisfied with the results button (door with arrow) to paste result-set into excel. Hopefully, this is understandable. It's helped me a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top