The Row Count Transformation in SSIS is used to counts the rows as they pass through a data flow and stores the final count in a variable. For example, If we want to inform the Manager to inform the number of rows this package is inserted then we can use Row Count Transformation for counting the rows and then use Script Task to send an e-mail message to the Manager.
In SQL Server Integration Services, Row Count Transformation will not the update the variable value until the last row of the source data has passed through the Row Count Transformation. So, we can’t use the updated values in the middle. Let us design one package so that we can understand this transformation better.
Row Count Transformation in SSIS 2014 Example
STEP 1: Drag and drop the data flow task from the toolbox to control flow and rename it as Row Count Transformation in SSIS 2014
STEP 2: This transformation stores counted rows information in variable only, so before using this transformation we need to create a variable on the Variables tab and add an integer variable to the package, as shown in below Figure.
Right click on the Control Flow region will open the context menu with multiple options. Select the Variables option from the context menu to create a variable.
In this case, we’ve chosen to add a variable named NumberOfRows of integer type and assigned value to 0.
Double click on the data flow task will open the data flow tab.
STEP 3: Drag and drop OLE DB Source, Row Count Transformation from toolbox to data flow region
STEP 4: Double click on OLE DB source in the data flow region will open the connection manager settings and provides space to write our SQL statement.
SQL Command we used in the above figure
INNER JOIN [FactResellerSales] AS RESELLER ON
[DimGeography].[SalesTerritoryKey] = RESELLER.[SalesTerritoryKey]
ORDER BY [EnglishCountryRegionName],[StateProvinceName]
STEP 5: Click on columns tab to verify the columns. In this tab we can uncheck the unwanted columns also.
STEP 6: The final step is to configure the Row Count transformation. Double click on the Row Count Transformation will open small Row Count Window to select the User defined Variable from the drop down. Here we are selecting the already created variable (NumberOfRows).
Or you can configure the Row Count Transformation with more Traditional approach. Right click on the Row Count Transformation will open the context menu with multiple options. Here select the Show Advanced Editor option from the context menu as shown in below screenshot.
This will open the Advanced Editor of the Row Count Transformation. Within the Component Properties tab choose the VariableName property of the Row Count Editor, shown in Figure below and associate the variable we created before (NumberOfRows)
STEP 7: Go to Control flow region and Drag and drop the Script Task from toolbox to Control Flow Region and drag the double-click on it to configure
STEP 8: Select the user defined variable as a read write variable as shown in below figure
STEP 9: Click ok and then click on Edit Script button to open class file
Type the following lines of code in Main method
String Message = Dts.Variables["User::NumberOFRows"].Value.ToString();
NOTE: Here I used C# programming language code and I am sorry for VB.Net people. Hope you can understand this code.
Close the class file and Let’s run the Row Count Transformation package. From the below screenshot you can observe that it is displaying the Message Box with Number of Rows information.
Let us see the data Flow region whether the transformation is giving the correct Result or not
Remember, Until you click the ok button Script task will be in running mode. Once you close the Message Box then the Green Tick Mark will be show
You can observe the message box displaying the number of rows passed through that transformation.
NOTE: This transformation has one input and one output. It does not support an error output.
Thank you for Visiting Our Blog