Solved

Nested For Each

Posted on 2010-11-10
4
761 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

707 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

12 Experts available now in Live!

Get 1:1 Help Now