dbTalk Databases Forums  

Iterative loop through SQL expression

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Iterative loop through SQL expression in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mike Coffey
 
Posts: n/a

Default Iterative loop through SQL expression - 05-15-2006 , 01:17 PM






Very long story short, I have a group of steps in an SSIS package that I
would like to loop through based on the values returned from an SQL SELECT
statement. I've tried to set up the ForEach Loop container to process the
statement, but have been unsuccessful. How do I tell the container to
iteratively process the key values returned by the SELECT?

Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Iterative loop through SQL expression - 05-15-2006 , 01:28 PM






Hello Mike,


So you have a SELECT statement that returns a rowset. You want to loop over
the rowset and execute n Tasks?

Read the SELECT statement into a Rowset variable (object)

Now in the ForEach loop use the ForEach ADO Enumerator type and add your
variable when prompted.

Is this what you want to do ?


Allan



Quote:
Very long story short, I have a group of steps in an SSIS package that
I would like to loop through based on the values returned from an SQL
SELECT statement. I've tried to set up the ForEach Loop container to
process the statement, but have been unsuccessful. How do I tell the
container to iteratively process the key values returned by the
SELECT?




Reply With Quote
  #3  
Old   
Mike Coffey
 
Posts: n/a

Default Re: Iterative loop through SQL expression - 05-15-2006 , 01:50 PM



Allan:

That should do it. Thanks for the assist.

mc

"Allan Mitchell" wrote:

Quote:
Hello Mike,


So you have a SELECT statement that returns a rowset. You want to loop over
the rowset and execute n Tasks?

Read the SELECT statement into a Rowset variable (object)

Now in the ForEach loop use the ForEach ADO Enumerator type and add your
variable when prompted.

Is this what you want to do ?


Allan



Very long story short, I have a group of steps in an SSIS package that
I would like to loop through based on the values returned from an SQL
SELECT statement. I've tried to set up the ForEach Loop container to
process the statement, but have been unsuccessful. How do I tell the
container to iteratively process the key values returned by the
SELECT?





Reply With Quote
  #4  
Old   
Todd C
 
Posts: n/a

Default Re: Iterative loop through SQL expression - 11-20-2006 , 12:04 PM



Mike: Can you tell me EXACTLY how you accomplished this scenario? I
understand Allan's GENERAL instructions, but I can't seem to put it into
practice.

For example, Allan says,
Quote:
Read the SELECT statement into a Rowset variable (object)
GREAT! How do I do that? Do I need a separate Data Flow to make that happen?

Once I do that, how do I retrieve the values from each row?

Thanks in advance.

Todd C

"Mike Coffey" wrote:

Quote:
Allan:

That should do it. Thanks for the assist.

mc

"Allan Mitchell" wrote:

Hello Mike,


So you have a SELECT statement that returns a rowset. You want to loop over
the rowset and execute n Tasks?

Read the SELECT statement into a Rowset variable (object)

Now in the ForEach loop use the ForEach ADO Enumerator type and add your
variable when prompted.

Is this what you want to do ?


Allan



Very long story short, I have a group of steps in an SSIS package that
I would like to loop through based on the values returned from an SQL
SELECT statement. I've tried to set up the ForEach Loop container to
process the statement, but have been unsuccessful. How do I tell the
container to iteratively process the key values returned by the
SELECT?





Reply With Quote
  #5  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Iterative loop through SQL expression - 11-20-2006 , 12:59 PM



Hello Todd,

For reading into a Rowset variable have a look here

http://www.sqlis.com/default.aspx?59


You could also do the assignment through an ExecuteSQL task

http://www.sqlis.com/default.aspx?58


Regards

Allan Mitchell
Konesans Ltd
T +44 7966 476 572
F +44 2071 008 479
http://www.konesans.com

Quote:
Mike: Can you tell me EXACTLY how you accomplished this scenario? I
understand Allan's GENERAL instructions, but I can't seem to put it
into practice.

For example, Allan says,

Read the SELECT statement into a Rowset variable (object)

GREAT! How do I do that? Do I need a separate Data Flow to make that
happen?

Once I do that, how do I retrieve the values from each row?

Thanks in advance.

Todd C

"Mike Coffey" wrote:

Allan:

That should do it. Thanks for the assist.

mc

"Allan Mitchell" wrote:

Hello Mike,

So you have a SELECT statement that returns a rowset. You want to
loop over the rowset and execute n Tasks?

Read the SELECT statement into a Rowset variable (object)

Now in the ForEach loop use the ForEach ADO Enumerator type and add
your variable when prompted.

Is this what you want to do ?

Allan

Very long story short, I have a group of steps in an SSIS package
that I would like to loop through based on the values returned from
an SQL SELECT statement. I've tried to set up the ForEach Loop
container to process the statement, but have been unsuccessful.
How do I tell the container to iteratively process the key values
returned by the SELECT?




Reply With Quote
  #6  
Old   
Todd C
 
Posts: n/a

Default Re: Iterative loop through SQL expression - 11-22-2006 , 07:14 AM



Allan: Thank you for the links. Got those pages bookmarked for future issues!

I was able to accomplish this with help from your book, "Pro SQL 2005 IS",
with an Execute SQL Task (outside), a Script Task (inside), and the ForEach
container. The SQL Task reads the recordset into an object variable, the
ForEach shreds it to the assigned variables for each respective column, and
the Script builds dynamic SQL and assignes it to another string variable for
use in the Data Source.

The ultimate goal was to iterate through a bunch of tables that had
identical schema design and send them all to a Fact table in the warehouse.

Yes, a simple UNION ALL would work, but I wanted a way to dynamicly choose
which tables to pull from based on entries in a meta table.

Thanks for your suggestions.

Keep them coming!

Todd C

"Allan Mitchell" wrote:

Quote:
Hello Todd,

For reading into a Rowset variable have a look here

http://www.sqlis.com/default.aspx?59


You could also do the assignment through an ExecuteSQL task

http://www.sqlis.com/default.aspx?58


Regards

Allan Mitchell
Konesans Ltd
T +44 7966 476 572
F +44 2071 008 479
http://www.konesans.com

Mike: Can you tell me EXACTLY how you accomplished this scenario? I
understand Allan's GENERAL instructions, but I can't seem to put it
into practice.

For example, Allan says,

Read the SELECT statement into a Rowset variable (object)

GREAT! How do I do that? Do I need a separate Data Flow to make that
happen?

Once I do that, how do I retrieve the values from each row?

Thanks in advance.

Todd C

"Mike Coffey" wrote:

Allan:

That should do it. Thanks for the assist.

mc

"Allan Mitchell" wrote:

Hello Mike,

So you have a SELECT statement that returns a rowset. You want to
loop over the rowset and execute n Tasks?

Read the SELECT statement into a Rowset variable (object)

Now in the ForEach loop use the ForEach ADO Enumerator type and add
your variable when prompted.

Is this what you want to do ?

Allan

Very long story short, I have a group of steps in an SSIS package
that I would like to loop through based on the values returned from
an SQL SELECT statement. I've tried to set up the ForEach Loop
container to process the statement, but have been unsuccessful.
How do I tell the container to iteratively process the key values
returned by the SELECT?





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.