Solved

Nested For Each

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

863 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

24 Experts available now in Live!

Get 1:1 Help Now