Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite Excel destination in SSIS?

Tags:

ssis

I have created a package to fetch data from two SQL Server tables, and using merge join combined this data, then stored the result into an Excel destination.

The first time it works fine. The second time it stores repeated data in the Excel file.

How do I overwrite the Excel file rows?

like image 283
jay Avatar asked Nov 05 '11 06:11

jay


People also ask

How do I add destinations in Excel SSIS?

On the SSIS menu, select New connection. In the Add SSIS Connection Manager dialog box, select EXCEL and then Add. Create the connection manager at the same time that you configure the Excel Source or the Excel Destination on the Connection manager page of the Excel Source Editor or of the Excel Destination Editor.

How do I create a dynamic destination in Excel SSIS?

Select the properties for Excel Connection Manager instance, Click on the ellipsis for 'Expressions 'property and set an expression for 'ExcelFilePath' to a variable with a valid path to an excel file, this takes cares of the connection string.


5 Answers

Yes, Possible!

Here is the solution:

First go to your Excel Destination Click to New Button next to Name of Excel Sheet, copy the DML query inside. Then put an Execute SQL Task into your Control Flow and connect it to your data flow that contains Excel destination. Set the Connection Type To Excel, Set the Connection to your Excel Destination's Excel Connection Manager, go to SQL Statement and type :

Drop TABLE `put the name of the sheet in the excel query you just copied`
Go

finally paste the query after it.

It is all you need to do to solve the problem.

You can refer to this link for a complete info: http://dwhanalytics.wordpress.com/2011/04/07/ssis-dynamically-generate-excel-tablesheet/

like image 103
Jami Avatar answered Oct 21 '22 04:10

Jami


Unfortunately the Excel connection manager does not have a setting that allows overwriting the data. You'll need to set up some file manipulation using the File System Task in the Control Flow.

There are several possibilities, here's one of them. You can create a template file (which just contains the sheet with the header) and prior to the Data Flow Transformation a File System Task copies it over the previously exported file.

The File System Task (MSDN)

like image 24
Valentino Vranken Avatar answered Oct 21 '22 05:10

Valentino Vranken


Yes, Possible!

Using SSIS we can solve this problem:

first of all, crate an Excel format file (Structure Format using Excel Connection Manager) at one location as a template file. Then create a copy of that excel file using FILE SYSTEM TASK in another location and make sure that SET OverwriteDestination=True. Finally, using a data flow task, insert data into the new copied file. whenever we want insert data, it will create a copy of the template excel file and then load the data.

enter image description here

like image 30
manoj Avatar answered Oct 21 '22 05:10

manoj


For Excel it will append data. There is no such option available for overwriting data.

You have to delete and recreate the file through the File System task.

like image 42
Harish Avatar answered Oct 21 '22 05:10

Harish


Using a CSV file with flat-file connection manager would serve your purpose of overwriting.

like image 42
Sri Krishna R Avatar answered Oct 21 '22 03:10

Sri Krishna R