-1

How can I export a table from sql to an excel using SSIS script? In addition I have to maintain an excel template so everytime it matches the header name and export data into it.

bmsqldev
  • 2,627
  • 10
  • 31
  • 65
SaNa3819
  • 337
  • 5
  • 19

2 Answers2

0

There are two ways (as I know) to get data into Excel file from SQL Server database.

  1. SSIS Package
  2. Simply import data from SQL Server to Excel file

In the first approach, after creating the SSIS package, you can add a schedule for the SSIS package execution using SQL Server agent.

OR

Import the data into Excel from SQL Server, using the tab DATA -> Existing Connection -> SQL Server. You can write specific SQL to import data or simply import the table. Adding more, using the Refresh All under the same DATA tab, you can refresh the data anytime & be in sync with the SQL Server table.

Community
  • 1
  • 1
Aditya
  • 2,299
  • 5
  • 32
  • 54
0

You can use the tsql query/stored procedure with openrowset in execut SQL task. Here is a link to another post with examples how to do it (use Openrowset)

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926

If this is not an option then maybe c# or Vb.net with usage of datatables. You can define the structure of the datatable, I.e. Columns their data types (.net types). Then you can save a datatable to excel. Here is a link which hopefully will help you.

Convert datatable to excel 2007(.xlsx)

Community
  • 1
  • 1
Dariusz Bielak
  • 415
  • 2
  • 7