Avatar of shragi
shragi
Flag for India asked on

sql stored procedure to export to excel

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,
Microsoft SQL ServerDB Reporting ToolsSQL

Avatar of undefined
Last Comment
Valliappan AN

8/22/2022 - Mon
Valliappan AN

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.
awking00

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).
shragi

ASKER
@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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
shragi

ASKER
@valliapan
Yup checked all the things that u mentioned but not sure how to write stored procedure to do it
SOLUTION
Jim Horn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
shragi

ASKER
@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
ASKER CERTIFIED SOLUTION
Valliappan AN

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.