Hakkaino
Hakkaino

Reputation: 1

Writing MS SQL Query results to Excel file

I am planning to create a stored procedure that will query certain information from a database then write the information to the Excel file. I am planning to execute the stored procedure via Windows Task Scheduler. I have already created the queries but what is lacking is the command that would write to the Excel file. This is for the purpose of auto reporting. I've read about the OPENROWSET but have no idea how it works.

Thanks for your answers in advance.

Upvotes: 0

Views: 1060

Answers (1)

Karthikeyan Anbarasan
Karthikeyan Anbarasan

Reputation: 11

Don’t use OPENROWSET it is read-only. Use the OPENDATASOURCE you can read & write data into it.

Insert into 
OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0', 'Data Source={Your Excel File Path};Extended Properties=Excel 8.0')...[SheetName$]
Values (....)

Upvotes: 1

Related Questions