x
login about faq Site discussion (meta-askssc)

Export Sql Server ResultSet to Excel Sheet

Hi

I need the Sql Server Resultsets to be exported to Excel Sheets. There will be multiple queries and it is not fixed. Hence we CANNOT create the destination Excel Sheets in advance.

I'm aware of the following script, but for this the excel sheet has to be created in advance...

INSERT INTO OPENROWSET 
('MICROSOFT.JET.OLEDB.4.0', 
'Excel 8.0; Database=\\dba\Share\Test.xls;HDR=NO;IMEX=2',
'select * from [Sheet1$]' 
)
 SELECT * from category 

Rgds
Mohan Kumar VS

more ▼

asked Jul 01 '11 at 05:25 AM in Default

Mohan Kumar gravatar image

Mohan Kumar
204 12 18 20

(comments are locked)
10|1200 characters needed characters left

3 answers: sort voted first

Not 100% on the OPENROWSET, but BCP will allow you to do this.

MSDN BCP

more ▼

answered Jul 01 '11 at 05:49 AM

sp_lock gravatar image

sp_lock
8.1k 20 26 29

Thanks a lot.

Jul 03 '11 at 11:39 PM Mohan Kumar
(comments are locked)
10|1200 characters needed characters left

Another option is to use Powershell. Within Powershell you can create Excel objects (sheets), run sql and export data - seems like a candidate!

Maybe start with this link : http://sqlserverpedia.com/blog/sql-server-bloggers/powershell-and-sql/

more ▼

answered Jul 01 '11 at 09:01 AM

Kev Riley gravatar image

Kev Riley ♦♦
46.1k 39 43 69

Thanks a lot.

Jul 03 '11 at 11:39 PM Mohan Kumar
(comments are locked)
10|1200 characters needed characters left

Hi could you please let me know some more info about this query....

INSERT INTO OPENROWSET 
('MICROSOFT.JET.OLEDB.4.0', 
'Excel 8.0; Database=\\dba\Share\Test.xls;HDR=NO;IMEX=2',
'select * from [Sheet1$]' 
)
 SELECT * from category ....
more ▼

answered Nov 19 '12 at 10:24 AM

pan_cbe gravatar image

pan_cbe
0

I would suggest you ask this as a new question, indicating what you want to know...

Nov 19 '12 at 11:10 AM ThomasRushton ♦
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x98
x26
x26

asked: Jul 01 '11 at 05:25 AM

Seen: 2511 times

Last Updated: Nov 19 '12 at 11:10 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.