For Each File Logic

  • A little new to SSIS, but i'm definitely a deep dive programmer.

    my question is more of a setup or strategy for a file full of folders, where filenames with a certain pattern would go to one dataflow task, and files with a different pattern in the filename would go to another.

    so if you had a dozen or so data flows, one for each pattern, which in turn get their ETL done inside, do you use a dozen seperate ForEach loops, which use an expression to filter the "right" pattern, or can it be done with a single ForEach Loop?

    it seems to me that one loop with conditional logic to process a file is better than 12 little loops.

    is there a technique to do that conditional data flow logic?

    i can be lazy and have twelve like these below, but it just doesn't feel right to me.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • What exactly do you mean with "that conditional data flow logic"?

    Having seperate for each loop containers will exploit parallellism to the max. Although 12 seems a bit excessive 🙂

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Thanks for looking Koen!

    what i mean, is, say you have a folder of files, some file names contain "_Product_" in their names, others contain "_Patient_" or "_Sections_" in their names.

    there's at least half a dozen matching files for each substring that i would be processing/looking for.

    so my "conditional logic" i was asking about, is can i use a single loop to direct files that meet pattern "*_Product_'.txt" to go to a specific Data Flow, and another pattern to a different data flow?

    effectively an if/case/switch: if Instring(filename,pattern) > 0 then ...

    or do i just make a dozen seperate loops and walk away?

    my prelim SSIS package I'm starting out with is just using lots of seperate loops, and it just bothered me.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • It is possible:

    * store the current file name in a variable (you can configure this in the for each loop)

    * inspect the file name with a script task. According to the value found, set another variable (for example: if _Product_ was found, store Product in @typeFile variable)

    * connect the script task to 12 data flow tasks (assuming each file has a different layout). In the precedence constraint, use an expression. For example: @typeFile == "Product"

    The downside is that you are processing file per file.

    While 12 for each loops may seem ugly, it will probably be much faster.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Koen Verbeeck (3/7/2014)


    It is possible:

    * store the current file name in a variable (you can configure this in the for each loop)

    * inspect the file name with a script task. According to the value found, set another variable (for example: if _Product_ was found, store Product in @typeFile variable)

    * connect the script task to 12 data flow tasks (assuming each file has a different layout). In the precedence constraint, use an expression. For example: @typeFile == "Product"

    The downside is that you are processing file per file.

    While 12 for each loops may seem ugly, it will probably be much faster.

    I agree. Even though it's bit tedious, 12 FE loops would be much faster as they can start in parallel.

    You can just design one FE loop and copy and paste it 11 times and modify each one accordingly.

    --

    SQLBuddy

  • thank's guys; that's the path i'm going down now...multiple for loops.; i'd do it differently in c# or vb.net,

    SSIS for me is a middle layer of complexity inserted between me and the programming behind the scenes; it's a little wierd for me still.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply