- C# Scripts
- DWH INTERVIEW QUESTIONS
- MS Dynamics AX 2012 R2 Video Tutorial
- Project / Work Support
- SQL SERVER DBA INTERVIEW QUESTIONS
- SQL SERVER DBA Video Tutorial
- SQL Server / TSQL Tutorial
- SQL Server 2016
- SQL Server Scripts
- SSIS INTERVIEW QUESTIONS
- SSIS Video Tutorial
- SSRS INTERVIEW QUESTIONS
- SSRS Video Tutorial
- TSQL INTERVIEW QUESTIONS
- Team Foundation Server 2013 Video Tutorial
- Team Foundation Server 2015 Video Tutorial
- Windows 10
- Windows Server 2012 R2 Installation Videos
SSIS - Read Top X Rows From Flat File / Excel File OR Range OF Rows
Here is our solution, We will be reading the flat file by using Flat File Source, after that we will use Script component as transformation to generate the sequence number for each of the record. Once we have the sequence number we will be using Conditional Split to get top X records or range of rows depending upon our requirement.
Here is sample data that I am using for this sample package. I have 25 records. Please create sample file on your desktop or any drive you want.
Create new SSIS Package and Drag Data Flow task to Control Flow pane. Bring Flat File Source to Data Flow Pane and configure as shown below
Bring Script Component and connect your Flat File Source to Script Component, When you will bring Script Component to Data Flow Pane it will prompt you to Choose if you want to use Script Component as Source, Destination or Transformation,Choose Transformation.
After that configure as shown below
Choose the columns you want to Pass through
Add a new output column Seqno as shown below
Click on Script in Script Transformation Editor and Then Edit Script and paste below code or write what is shown in Red
/* Microsoft SQL Server Integration Services Script Component
* Write scripts using Microsoft Visual C# 2008.
* ScriptMain is the entry point class of the script.*/
public class ScriptMain : UserComponent
public override void PreExecute()
Add your code here for preprocessing or remove if not needed
public override void PostExecute()
Add your code here for postprocessing or remove if not needed
You can set read/write variables here, for example:
Variables.MyIntVar = 100
public override void Input0_ProcessInputRow(Input0Buffer Row)
RowNumber += 1;
Row.Seqno = RowNumber;
Add your code here
Bring Conditional Split Transformation and connect Script Component to it and write expressions to get only top 10 rows. You can also defined range if you your requirement is let's see read records from 5 to 15.
Let's execute our package and see the output , It should only display top 10 records. I used Multicast and Data Viewer just to display the records. In real time scenario you will be inserting these records to some destination table/file.