Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

For Each File Logic Expand / Collapse
Author
Message
Posted Friday, March 7, 2014 5:42 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:29 AM
Points: 12,881, Visits: 31,808
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son


  Post Attachments 
dataflow.png (57 views, 14.84 KB)
Post #1548696
Posted Friday, March 7, 2014 5:53 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:51 AM
Points: 13,252, Visits: 10,135
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




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1548700
Posted Friday, March 7, 2014 6:37 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:29 AM
Points: 12,881, Visits: 31,808
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1548712
Posted Friday, March 7, 2014 6:44 AM This worked for the OP Answer marked as solution


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:51 AM
Points: 13,252, Visits: 10,135
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.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1548715
Posted Friday, March 7, 2014 11:14 AM This worked for the OP Answer marked as solution
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 4:23 PM
Points: 1,194, Visits: 2,209
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
Post #1548833
Posted Friday, March 7, 2014 11:59 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:29 AM
Points: 12,881, Visits: 31,808
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1548848
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse