SSIS - How to skip last row in the SSIS data flow
To ignore the last row you have to do the following steps:
- Add a
DataFlow Task
(let's name itDFT RowCount
) - Add a Global Variable of Type
System.Int32
(Name: User::RowCount) - In this DataFlow Task add a
Flat File Source
(The file you want to import) - Add a
RowCount
component next to theFlat File Source
- Map the
RowCount
result to the variableUser::RowCount
- Add Another
DataFlow Task
(let's name itDFT Import
)
- In
DFT Import
add aFlat File Source
(File you need to Import) - Add a
Script Component
next to theFlat File Source
- Add
User::RowCount
Variable to the Script ReadOnly Variables
- Add an Output Column of type
DT_BOOL
(Name:IsLastRow
)
- In the Script Window write the following Script
Dim intRowCount As Integer = 0 Dim intCurrentRow As Integer = 0 Public Overrides Sub PreExecute() MyBase.PreExecute() intRowCount = Variables.RowCount End Sub Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) intCurrentRow += 1 If intCurrentRow = intRowCount Then Row.IsLastRow = True Else Row.IsLastRow = False End If End Sub
- Add a
Conditional Split
Next to the Script Component - Split Rows using the Following Expression
[IsLastRow] == False
- Add the
OLEDB Destination
next to the conditional Split
Side Note: if you want to ignore rows for another case (not last row) just change the script written in the script component to meet your requirements
Comments
Post a Comment