none
Split collection to multiple foreach RRS feed

  • Question

  • Hello,

     I have a SQL Task that return 300 Records from DB .

    I need to Split these records to three foreach container .  each container has 100 records .

     how can I implement that ?

    Thanks


    ASk

    Sunday, March 26, 2017 7:07 AM

All replies

  • Hi ,

    You can use the conditional split, while devide your data to 3 buckets :


    SELECT 
        tbl.*
    ,   (ROW_NUMBER() OVER (ORDER BY (SELECT NULL))) % 3 AS bucket
    FROM 
        DataTable AS tbl

    Regards, David .

    Sunday, March 26, 2017 9:07 AM
  • Hello ,

     Thanks for your reply .

     The Split Condition is available only Data flow not on the control flow . on the other hand the foreach container not available on data flow .

     Thanks 


    ASk

    Sunday, March 26, 2017 9:41 AM
  • https://www.simple-talk.com/sql/ssis/implementing-foreach-looping-logic-in-ssis/

    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance
    SQL Server Integration Services: Business Intelligence

    Sunday, March 26, 2017 10:42 AM
  • Hello ,

     Thanks for your reply .

     The Split Condition is available only Data flow not on the control flow . on the other hand the foreach container not available on data flow .

     Thanks 


    ASk

    why not create a simple for loop based on a variable which is initialized to 1 and loops until 3 and put your foreach loop inside it. for foreach loop make condition like seq between

    ((counter-1) * 100) + 1 to counter * 100

    where counter is variable used inside for loop and seq a unique field generated using your key field(s) inside for each loop


    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    ----------------------------
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

    Sunday, March 26, 2017 10:54 AM