Solved

Nested For Each

Posted on 2010-11-10
4
764 Views
Last Modified: 2013-11-10
Hi,

I'm not sure if is possible in SSIS but I have 2 DataSet's and I would like to do a nested loop.

Therefore:

For Each Row in DataSet1 (loop through each header)
          For Each Row in DataSet2 (loop through the details that are equal to the header)

To help you understand DataSet1 is the Headers and DataSet2 is the Details.  Additionally the Header Rows are each numbered and the Detail Rows have the unique header row number in them.

I know I can do this in Scripting tasks but I just wondered if there was a proper/elegant way of doing it in SSIS.

Any help greatly appreciated.

Mike
0
Comment
Question by:hydev
4 Comments
 
LVL 8

Accepted Solution

by:
raulggonzalez earned 250 total points
ID: 34101329
Why not create 1 dataset with all the rows?


And you can loop just once.


hope it helps.


Cheers
SELECT * 
FROM Headers AS H
LEFT JOIN Details AS D
ON D.headerID = H.ID

Open in new window

0
 
LVL 16

Assisted Solution

by:EvilPostIt
EvilPostIt earned 250 total points
ID: 34101505
If you are not using a SQL data source and are in fact importing from files etc then you have the following options.

1)   Yes you can do a nested loop although you will have to do it using variables. Also this will be row based and could take longer if there a many rows.
2)   You may be able to get the results you are after by doing this in a data flow task using the merge or merge join transformations.

It really depends on what you want to do. For example you have not specified if you want to perform and action for each rows.

If you could give a bit more detail as far what you want the entire package to do i should be able to give a more precise answer.
0
 
LVL 18

Expert Comment

by:deighton
ID: 34101907
if this is .net datatables and datasets then you can set up and use data relations to return all the child rows for a parent
0
 

Author Closing Comment

by:hydev
ID: 34102324
You have both given me ideas to possible solutions so thanks.  
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now