Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Foreach loop help

Author  Topic 

sundevilscott
Starting Member

12 Posts

Posted - 2011-09-27 : 12:30:53
Hello All -

I am newer to SSIS and need some assistance with a foreach loop. I have a sproc that requires an ID number and a date to be pased to it. So it might look like this:

EXEC dbo.get_xmlcode_staging @cruisebookrecno = 1424604, -- int
@last_update_date = '2011-09-22 12:49:11.710' -- datetime

It basically spits out a string into a column. So in my table I have 2 columns like this:

cruisebookrecno INT
xml Varchar(MAX)

In that table I have a list of ID numbers and I need to learn how to pass those numbers to my sproc. I have used the Foreach file enumirator but am not sure how and what to use here.

Thank you in advance.

Scott

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-27 : 12:47:11
you should be using for each loop with ado.net enumerator. first you need to create a object type variable and use it to store resultset of your table query. This you can do inside a execute sql task by giving query and mapping variable in resultset pane. then mapping this variable in for each loop will make sure it iterates through values in variable. Use another variable of type int to hold each id value inside the loop and then use that variable to pass the value to stored proc again inside another sql task. the parameter can be represented using ? symbol inside sql task so it will be like EXEC dbo.get_xmlcode_staging ?, '2011-09-22 12:49:11.710' then map it in parameters tab.
so in short package will be like

exec sql task (to populate object variable --> for each loop

inside loop it will be

exec sql task to call sp.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -