Solved

sql stored procedure to export to excel

Posted on 2014-12-19
7
803 Views
Last Modified: 2015-01-21
Hi - I am trying to write a stored procedure to export the data from a table to excel document.
May I know how to do this, I tried to in the below way but that did not work.

INSERT INTO OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\Report\test.xls;','Select * from [GasEUR$]')
SELECT * FROM Report_temp

Error: Cannot create an instance of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".


The excel document was not created before hand so is it possible to write a stored procedure that creates the excel document and exports data from table Report_temp to that excel.

Thanks,
0
Comment
Question by:shragi
7 Comments
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 40510765
1) Please check if you have installed the Jet drivers or MS Office drivers.
2) That you have the write/read permissions for the folder you are accessing.
3) If its a 64 bit machine, then you may need to use 64 bit driver connection string for excel.

HTH.
0
 
LVL 32

Expert Comment

by:awking00
ID: 40510923
I have always found it easier to import data from the database into an excel spreadsheet rather than the other way around. Open excel and select the data tab, select From Microsoft Query from the From Other Sources menu in the Get External Data section of the spreadsheet. From there you can make an ODBC connection to your database, then follow the Query Wizard to import data from the database table(s).
0
 

Author Comment

by:shragi
ID: 40511027
@awking
I am trying to automate the process by writing stored procedure to export the data from table to excel becoz I am need to do this every day, so ur method needs manual intervention
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:shragi
ID: 40511028
@valliapan
Yup checked all the things that u mentioned but not sure how to write stored procedure to do it
0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 40511719
Give this a whirl -->  Microsoft Excel & SQL Server:  Self service BI to give users the data they want, which is an article I wrote on how to hotwire SQL Server Stored Procedures (you can use a table if it floats your boat) into Excel.
0
 

Author Comment

by:shragi
ID: 40513348
@Jim - There is no stored procedure in that link that helps me to export data to excel.

My requirements:

1) write a stored procedure that exports table data to excel
2) not exporting thru excel
3) I want to call that stored procedure every day and that stored procedure should create an excel when ever i call it.

is this possible ?

THanks
0
 
LVL 9

Accepted Solution

by:
Valliappan AN earned 250 total points
ID: 40521440
Hi,

Please check this link on how to install the required drivers, and use the query for Access or Excel:

OLE DB Provider for Jet

HTH.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now