SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


For Each File Logic


For Each File Logic

Author
Message
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28213 Visits: 39955
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!

Attachments
dataflow.png (65 views, 14.00 KB)
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27385 Visits: 13268
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28213 Visits: 39955
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!

Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27385 Visits: 13268
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
sqlbuddy123
sqlbuddy123
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2376 Visits: 2243
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
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28213 Visits: 39955
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!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search