How to Export data to Excel in SQL Server using SQL Jobs

Atanu Roy picture Atanu Roy · Sep 27, 2013 · Viewed 23.8k times · Source

I need to export the data from a particular table in my database to Excel files (.xls/.xlsx) that will be located into a shared folder into my network. Now the situation is like this -

  1. I need to use SQL SERVER Agent Jobs. 2.I need to generate a new excel file in every 2 minutes that will contain the refreshed data.

    I am using sql server 2008 that doesn't include BI development studio. I'm clueless how to solve this situation. First, I'm not sure how to export the data using jobs because every possible ways I tried had some issues with the OLEDB connection. The 'sp_makewebtask' is also not available in SQL 2008. And I'm also confused how to dynamically generate the names of the files.

    Any reference or solution will be helpful.

Answer

Dev picture Dev · Sep 27, 2013

Follow the steps given below :

1) Make a stored procedure that creates a temporary table and insert records to it.

2) Make a stored procedure that read records from that temporary table and writes to file. You can use this link : clickhere

3) Create an SQL-job that execute step 1 and step 2 sequentially.