locked
How to use RowCount with conditional split? RRS feed

  • Question

  • Hi Everyone,

    Can anyone please help me with the following scenario?

    - There is a table from which I am pulling the dataset. As per the row count in the dataset, I want to either create a text file based on the RowCount (i.e if rowcount=0; Create Emptied File  or if rowcount>0; Create Textfile).

    To achieve it, I used the below flow but it is not working as expected. Am I doing anything wrong? If yes, please guide me with proper solution.

    Currently, it goes to Case1 and Case2.

    Conditional Split cases:

    Case1 (There are no Record): If @rowcount ==0

    Case2 (There are Record) : If @rowcount>0

    What is happening now is, it goes to both cases.  It goes to There are records case and it also goes to there are no records case.  I am expecting to go to only one case which is "There are records" because there are records returning from the source.
    • Edited by GarinTiger Monday, April 29, 2019 7:22 PM
    Monday, April 29, 2019 4:03 PM

Answers

  • Hi GarinTiger,

    The Row Count Transformation stores the row count value in the variable only after the last row has passed through the transformation. Therefore, the value of the variable is not updated in time to use the updated value in the data flow that contains the Row Count transformation. You can use the updated variable in a separate data flow.


    According to your issue, we could add Execute SQL Task to get the number of rows.

    Notice in Execute SQL Task:

    ResultSet : Single row

    SQLStatement : select Count(*) from YourSourceTable

    Please refer to the similar case: How to use RowCount with conditional split?  .

    Best Regards,

    Mona Lv


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by GarinTiger Tuesday, April 30, 2019 12:14 PM
    Tuesday, April 30, 2019 5:24 AM

All replies

  • Hi GarinTiger,

    The Row Count Transformation stores the row count value in the variable only after the last row has passed through the transformation. Therefore, the value of the variable is not updated in time to use the updated value in the data flow that contains the Row Count transformation. You can use the updated variable in a separate data flow.


    According to your issue, we could add Execute SQL Task to get the number of rows.

    Notice in Execute SQL Task:

    ResultSet : Single row

    SQLStatement : select Count(*) from YourSourceTable

    Please refer to the similar case: How to use RowCount with conditional split?  .

    Best Regards,

    Mona Lv


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by GarinTiger Tuesday, April 30, 2019 12:14 PM
    Tuesday, April 30, 2019 5:24 AM
  • Thank you very much.

    This is perfect!

    Tuesday, April 30, 2019 12:14 PM