简体   繁体   中英

ssis using sql task to overwrite excel data

I have an ssis package that writes data to an excel destination, my issue is every time the package is run it adds the data to the end of the excel file and i want it to clear down the data and then insert. so i have added 2 sql tasks before my data flow task. the first drops the excel table, the second creates the table then the data flow task contains the excel connection.

在此处输入图片说明

it is failing on the create sql task with the following msg, i'm a little confused about how to go about it.

[Execute SQL Task] Error: Executing the query "CREATE TABLE `Excel Destination 1` (
`Name data..." failed with the following error: "Table 'Excel Destination 1' already exists.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

The issue is because i delete the excel destination in the control flow it falls over because file not there when it gets to the excel destination task as this then creates file?the create sql task uses same sql taken from excel destination editor next to name of excel sheet

CREATE TABLE `Excel Destination 1` (
`Name` VARCHAR(225),
`Postcode` VARCHAR(15),
`Date1` DATETIME,
`Date2` DATETIME,
`Date3` DATETIME,
`Date4` DATETIME,
`Date5` DATETIME,
`Date6` DATETIME,
`Date7` DATETIME,
`Date8` DATETIME,
`Date9` DATETIME,
`Date10` DATETIME,

)

I have also tried to use a File System Task to copy the file to a new location but this doesn't work it still just adds data to end of worksheet on each run rather than overwriting

Use this way to overwrite on destination 在此处输入图片说明

Have you tried using using a "template" excel file for each execution and renaming this? You can create a template based off the current excel document and place this in another folder. A generic name such as template or otherwise can be used, as long as the name is different from the file that's written to each time. The steps below outline this process further.

  • Use a File System Task to delete the excel file from the last execution.

  • Copy the template file to the location that you plan to write to your Excel Destination using another File System Task.

  • Rename the now copied template file to the file name used in the Connection Manager for your Excel Destination.
  • Execute your Data Flow Task to load the data into the new Excel file.


One thing to note, make sure that you delete the rows with data in the Excel file when you first create the template. If you only use the Clear Contents option, new data will be appended below.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM