We have a script task that processes a flatflat, inserts data into the database, then records any duplicates (via a stored proccedure) into a SQL table, which then passes it to a work flow task that looks up that table & writes all data into a file then trucates the table.
The problem is even when there is 0 errors recorded, it always writes an log flatfile.
Is there a way to write a flatfile where there is > 0 records in the duplicate log table?
Here is a possible option that might give you an idea of getting rid of Error file that have no records.
Here is step-by-step process on how to do this. In this example, I have used a csv file named
Country_State.csvcontaining countries and states as the source file.Scenario:
The sample package will read the file and then write to a text file named
Destination.txt. In this scenario, the error fileError.txtwill be created but later deleted if there are no errors. Here, I have the files stored in the pathc:\temp\Step by step flow:
Sourceconnection should point to the csv file pathc:\temp\Country_State.csv. Refer screenshot #2 for the contents of this file.Destinationconnection should point to a text file namedc:\temp\Destination.txt.Errorconnection should point to a text file namedc:\temp\Error.txt.ErrorCount.Data Flow Taskand then place aFile System Task.Expressionand paste the value@ErrorCount == 0in the Expression textbox.Sourceconnection manager.Destinationconnection manager.Row Counttransformation on the data flow tab and configure it to use the VariableUser:ErrorCount.Errorconnection manager.Errorconnection.Delete fileand set the SourceConnection toError. Refer screenshot #5.C:\tempbefore package execution are shown in screenshot #6.C:\tempafter package execution are shown in screenshot #9.Sourceconnection manager to integer (even though state names are strings) so that the data flow task redirects to theErroroutput.C:\tempafter Scenario 2 package execution are shown in screenshot #12. Notice that the file Destination.txt is present even though there were no successful rows. This is because the example deletes only the Error file if it is empty.Similar logic can be used to delete a empty Destination file.
Hope that helps.
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
Screenshot #5:
Screenshot #6:
Screenshot #7:
Screenshot #8:
Screenshot #9:
Screenshot #10:
Screenshot #11:
Screenshot #12: