Dinakar Nethi

A .NET/SQL Server Blog

<January 2009>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567


Navigation

About Me

Links

Subscriptions

Article Categories



Getting results of Query Analyzer into Excel

I am sure every SQL Developer/DBA must have had to do this more than once. There is no way to copy the heading from the result set if the output is a grid. If the output is in text you could cut/paste but there were formatting issues especially with datetime columns and with columns that are of varcahr types and have numbers in them..etc.
Recently I was asked to provide some data in an Excel sheet. Some of my columns had values as:
 
1855760000019
1855760000019
714 Gresham St
4615 Willow Street
2620 Santa Domingo Dr
 
I tried the methods from The Best Kept Secret About SQL Query Analyzer @ SQLServerCentral.com but I had formatting issues.
The issue I had was that the excel sheet was showing the values as 
1.85576E+12
1.85576E+12
714 Gresham St
4615 Willow Street
2620 Santa Domingo Dr
 
The only way I could get the actual value to show up was by formatting the cell content as "Fraction". Anything else I tried would either put comma's or currency symbols or percentage symbols. And I couldnt do this for each cell either since the result set was a few thousand records and there's no sense in going through each record and formatting. I have googled around and saw some tricks and hacks. Almost all of them dealt with some hacks from Query Analyzer. So I started looking at all the options available from Excel. Surely its not just some tool to pass around chunks of data. It can do more. And I did find my solution. So I thought I'd blog about this if any one else is in a similar situation.
 
Check this:
In Excel Under Data > Import External Data > New Database Query
 
If the Data Source is not already in there you can easily create one.
By default the option is selected. So click on OK and the wizard to create the new Data Source will appear.
 
  • Give a name
  • select the database driver (SQL Server is the last one in the list)
  • click "Connect"
  • Enter or choose the Server Name
  • Enter the type of connection - windows/sql
  • Click on "Options >>" Select the database from the list
  • If your data is coming straihgt from a table we wouldnt even be going through all this. So assuming the source is a query, leave the option for data source drop down blank and click "OK"
  • The Query Wizard to choose tables/columns appears. Click on "Cancel". Then close the window that pops up with table names again.
  • Click on the SQL tab. A new query editor pops up. Copy your query from the Query Analyzer into this editor.
  • Click on "yes" if it says the results cant be represented graphically.
  • The query results should appear in a tabular format.
  • Locate the button that says "Return Data" to the left of the SQL button and click it.
The results should be in the spread sheet now without losing any formatting or any unnecessary data conversions by excel.
 
Have fun.
 
 

posted on Thursday, April 06, 2006 2:36 PM by dinakar


# re: Getting results of Query Analyzer into Excel @ Saturday, August 11, 2007 9:29 AM

Cool...

Agias

# re: Getting results of Query Analyzer into Excel @ Saturday, August 11, 2007 11:01 PM

interesting

Marinos

# re: Getting results of Query Analyzer into Excel @ Sunday, August 12, 2007 12:11 AM

interesting

Efstratios

# re: Getting results of Query Analyzer into Excel @ Sunday, August 12, 2007 12:53 AM

Nice!

Charalampos

# re: Getting results of Query Analyzer into Excel @ Sunday, August 12, 2007 2:15 PM

interesting

Panayiotis

# re: Getting results of Query Analyzer into Excel @ Sunday, August 12, 2007 5:09 PM

Nice!

George

# re: Getting results of Query Analyzer into Excel @ Sunday, August 12, 2007 11:35 PM

Cool...

Romanos

# re: Getting results of Query Analyzer into Excel @ Monday, August 13, 2007 3:08 AM

Cool!

Harrys

# re: Getting results of Query Analyzer into Excel @ Tuesday, August 14, 2007 11:52 AM

Interesting...

Drymiotes

# re: Getting results of Query Analyzer into Excel @ Tuesday, August 14, 2007 12:46 PM

Sorry :(

Iacovos

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 15, 2007 2:06 AM

Cool!

Anastasios

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 15, 2007 8:02 AM

Nice

Sotirios

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 15, 2007 3:40 PM

Cool.

Kimon

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 15, 2007 9:03 PM

interesting

Achilles

# re: Getting results of Query Analyzer into Excel @ Thursday, August 16, 2007 9:57 AM

Nice...

Alexis

# re: Getting results of Query Analyzer into Excel @ Thursday, August 16, 2007 1:21 PM

Nice

Costas

# re: Getting results of Query Analyzer into Excel @ Thursday, August 16, 2007 3:36 PM

Cool!

Dighenis

# re: Getting results of Query Analyzer into Excel @ Thursday, August 16, 2007 8:35 PM

Nice

Eleni

# re: Getting results of Query Analyzer into Excel @ Thursday, August 16, 2007 8:59 PM

interesting

Stefanos

# re: Getting results of Query Analyzer into Excel @ Friday, August 17, 2007 12:25 AM

Nice!

Neophytos

# re: Getting results of Query Analyzer into Excel @ Friday, August 17, 2007 5:41 AM

Sorry :(

Demetri

# re: Getting results of Query Analyzer into Excel @ Friday, August 17, 2007 12:08 PM

interesting

Laurentios

# re: Getting results of Query Analyzer into Excel @ Friday, August 17, 2007 2:10 PM

Nice!

Adamantios

# re: Getting results of Query Analyzer into Excel @ Friday, August 17, 2007 9:04 PM

Cool...

Sebastianos

# re: Getting results of Query Analyzer into Excel @ Saturday, August 18, 2007 4:50 AM

Sorry :(

Gerasimos

# re: Getting results of Query Analyzer into Excel @ Saturday, August 18, 2007 1:15 PM

Sorry :(

Leandros

# re: Getting results of Query Analyzer into Excel @ Saturday, August 18, 2007 1:38 PM

Cool!

Vassilios

# re: Getting results of Query Analyzer into Excel @ Saturday, August 18, 2007 7:17 PM

Interesting...

Kristion

# re: Getting results of Query Analyzer into Excel @ Saturday, August 18, 2007 9:46 PM

Cool!

Demetris

# re: Getting results of Query Analyzer into Excel @ Sunday, August 19, 2007 7:40 AM

Interesting...

Vaggelis

# re: Getting results of Query Analyzer into Excel @ Sunday, August 19, 2007 2:20 PM

Cool.

Zacharias

# re: Getting results of Query Analyzer into Excel @ Sunday, August 19, 2007 3:16 PM

Nice

Yiorgos

# re: Getting results of Query Analyzer into Excel @ Sunday, August 19, 2007 10:16 PM

Cool.

Elias

# re: Getting results of Query Analyzer into Excel @ Monday, August 20, 2007 4:52 AM

interesting

Myron

# re: Getting results of Query Analyzer into Excel @ Monday, August 20, 2007 5:53 AM

Sorry :(

Giorgos

# re: Getting results of Query Analyzer into Excel @ Monday, August 20, 2007 12:46 PM

Interesting...

Evagelos

# re: Getting results of Query Analyzer into Excel @ Monday, August 20, 2007 2:23 PM

Nice!

Ilias

# re: Getting results of Query Analyzer into Excel @ Tuesday, August 21, 2007 12:26 PM

Interesting...

Kostas

# re: Getting results of Query Analyzer into Excel @ Tuesday, August 21, 2007 9:28 PM

Nice

Vasilios

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 22, 2007 6:18 AM

Cool...

Silvanos

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 22, 2007 12:44 PM

Cool!

Giorgos

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 22, 2007 7:10 PM

Interesting...

Yiannos

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 22, 2007 7:16 PM

Sorry :(

Constantine

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 22, 2007 8:16 PM

Nice...

Alexios

# re: Getting results of Query Analyzer into Excel @ Thursday, August 23, 2007 1:55 AM

Cool.

Charalambos

# re: Getting results of Query Analyzer into Excel @ Thursday, August 23, 2007 3:18 AM

Cool.

Vangelis

# re: Getting results of Query Analyzer into Excel @ Thursday, August 23, 2007 10:54 AM

Cool!

Dimitri

# re: Getting results of Query Analyzer into Excel @ Thursday, August 23, 2007 5:17 PM

Nice

Zacharias

# re: Getting results of Query Analyzer into Excel @ Thursday, August 23, 2007 8:23 PM

Interesting...

Antonis

# re: Getting results of Query Analyzer into Excel @ Thursday, August 23, 2007 11:20 PM

interesting

Sterghios

# re: Getting results of Query Analyzer into Excel @ Friday, August 24, 2007 4:23 AM

Nice

Vasilis

# re: Getting results of Query Analyzer into Excel @ Friday, August 24, 2007 6:36 AM

interesting

Othon

# re: Getting results of Query Analyzer into Excel @ Friday, August 24, 2007 2:28 PM

Nice!

Alexandros

# re: Getting results of Query Analyzer into Excel @ Friday, August 24, 2007 8:59 PM

Nice!

Matthaios

# re: Getting results of Query Analyzer into Excel @ Friday, August 24, 2007 11:29 PM

Nice!

Giatas

# re: Getting results of Query Analyzer into Excel @ Saturday, August 25, 2007 5:21 AM

Sorry :(

Michail

# re: Getting results of Query Analyzer into Excel @ Saturday, August 25, 2007 5:59 AM

Cool!

Kosmas

# re: Getting results of Query Analyzer into Excel @ Saturday, August 25, 2007 1:10 PM

Nice...

Themestoclis

# re: Getting results of Query Analyzer into Excel @ Saturday, August 25, 2007 3:13 PM

Interesting...

Costa

# re: Getting results of Query Analyzer into Excel @ Saturday, August 25, 2007 6:35 PM

Sorry :(

Aristotelis

# re: Getting results of Query Analyzer into Excel @ Saturday, August 25, 2007 10:01 PM

Cool!

Panagiote

# re: Getting results of Query Analyzer into Excel @ Saturday, August 25, 2007 11:22 PM

Cool.

Georghios

# re: Getting results of Query Analyzer into Excel @ Sunday, August 26, 2007 1:20 AM

Cool...

Petros

# re: Getting results of Query Analyzer into Excel @ Sunday, August 26, 2007 5:33 AM

Nice...

Stelios

# re: Getting results of Query Analyzer into Excel @ Sunday, August 26, 2007 6:55 AM

Sorry :(

Efstathios

# re: Getting results of Query Analyzer into Excel @ Sunday, August 26, 2007 1:37 PM

Sorry :(

Marinos

# re: Getting results of Query Analyzer into Excel @ Sunday, August 26, 2007 8:09 PM

Sorry :(

Zacharias

# re: Getting results of Query Analyzer into Excel @ Sunday, August 26, 2007 10:38 PM

Interesting...

Paulos

# re: Getting results of Query Analyzer into Excel @ Monday, August 27, 2007 1:01 AM

Cool...

Vaggelis

# re: Getting results of Query Analyzer into Excel @ Monday, August 27, 2007 8:00 AM

Nice

Andonios

# re: Getting results of Query Analyzer into Excel @ Monday, August 27, 2007 8:36 AM

Nice!

Kristion

# re: Getting results of Query Analyzer into Excel @ Monday, August 27, 2007 3:19 PM

interesting

Emmanuel

# re: Getting results of Query Analyzer into Excel @ Monday, August 27, 2007 9:00 PM

Nice!

George

# re: Getting results of Query Analyzer into Excel @ Tuesday, August 28, 2007 1:16 AM

interesting

Giatas

# re: Getting results of Query Analyzer into Excel @ Tuesday, August 28, 2007 8:03 AM

Sorry :(

Cletus

# re: Getting results of Query Analyzer into Excel @ Tuesday, August 28, 2007 3:50 PM

Cool.

Kyriakos

# re: Getting results of Query Analyzer into Excel @ Tuesday, August 28, 2007 4:43 PM

Cool!

Ari

# re: Getting results of Query Analyzer into Excel @ Tuesday, August 28, 2007 6:07 PM

Cool!

Tataki

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 29, 2007 3:20 AM

Nice...

Marko

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 29, 2007 5:30 AM

Nice

Leandros

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 29, 2007 1:49 PM

Nice...

Photios

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 29, 2007 3:40 PM

Sorry :(

Grigoris

# re: Getting results of Query Analyzer into Excel @ Wednesday, August 29, 2007 10:42 PM

Nice!

Vasilios

# re: Getting results of Query Analyzer into Excel @ Thursday, August 30, 2007 3:13 AM

interesting

Samaras

# re: Getting results of Query Analyzer into Excel @ Thursday, August 30, 2007 12:17 PM

Interesting...

Adamantios

# re: Getting results of Query Analyzer into Excel @ Thursday, August 30, 2007 2:42 PM

interesting

Constandinos

# re: Getting results of Query Analyzer into Excel @ Thursday, August 30, 2007 2:45 PM

Interesting...

Tasos

# re: Getting results of Query Analyzer into Excel @ Friday, August 31, 2007 6:21 AM

Cool!

Giannis

# re: Getting results of Query Analyzer into Excel @ Friday, August 31, 2007 11:22 AM

Nice

Iacovos

# re: Getting results of Query Analyzer into Excel @ Friday, August 31, 2007 12:46 PM

Cool...

Lambros

# re: Getting results of Query Analyzer into Excel @ Friday, August 31, 2007 4:40 PM

Nice...

Charilaos

# re: Getting results of Query Analyzer into Excel @ Friday, August 31, 2007 11:23 PM

Cool!

Stylianos

# re: Getting results of Query Analyzer into Excel @ Saturday, September 01, 2007 2:06 AM

Nice!

Socrates

# re: Getting results of Query Analyzer into Excel @ Saturday, September 01, 2007 4:32 AM

Cool.

Dion

# re: Getting results of Query Analyzer into Excel @ Saturday, September 01, 2007 7:47 AM

Interesting...

Miltiades

# re: Getting results of Query Analyzer into Excel @ Saturday, September 01, 2007 6:11 PM

Sorry :(

Vaggelis

# re: Getting results of Query Analyzer into Excel @ Saturday, September 01, 2007 10:24 PM

Cool...

Stephanos

# re: Getting results of Query Analyzer into Excel @ Saturday, September 01, 2007 11:12 PM

Nice

Stavros

# re: Getting results of Query Analyzer into Excel @ Saturday, September 01, 2007 11:17 PM

Interesting...

Efthimios

# re: Getting results of Query Analyzer into Excel @ Sunday, September 02, 2007 5:52 AM

Nice

Theophanis




Powered by Dot Net Junkies, by Telligent Systems