﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server 2005 Integration Services  / SSIS - ForEach From Variable Enumerator / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 01:56:43 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Please refer to this article http://www.rad.pasfu.com/index.php?/archives/18-Foreach-Loop-based-on-Variable-SSIS.html</description><pubDate>Wed, 03 Oct 2012 08:47:25 GMT</pubDate><dc:creator>Ravi Kumar V</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Yes, VStations is an Object.  I have not looked at the size of the array, no.</description><pubDate>Wed, 30 May 2012 10:16:27 GMT</pubDate><dc:creator>george.allen</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Have you tried debugging the size of the array?What is the data type of this? (Object?)Dts.Variables("User::VStations").</description><pubDate>Wed, 30 May 2012 10:01:19 GMT</pubDate><dc:creator>stuart.steedman</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>No better.  Still goes into that last iteration.</description><pubDate>Wed, 30 May 2012 09:49:36 GMT</pubDate><dc:creator>george.allen</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>I saw that reference to the Array over ArrayList and so I changed to the second instance, and this also has the same problem.  It iterates through the values I give it and then doesn't stop, but goes on to do one with a 0 value.  I have seen posts where I could cause a Fail to get out of the loop, but why fail when it is clear that it did not, but just never stop.</description><pubDate>Wed, 30 May 2012 09:27:43 GMT</pubDate><dc:creator>george.allen</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Try this:Dim arr() As Stringarr = "636, 437, 618, 568".Split(",")Dts.Variables("User::VStations").Value = arr Stu</description><pubDate>Wed, 30 May 2012 09:26:11 GMT</pubDate><dc:creator>stuart.steedman</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Referring back to my prior post:"The crucial part was to set up the object as an Array, rather than an ArrayList."Can't remember back why this was...Stu</description><pubDate>Wed, 30 May 2012 09:17:53 GMT</pubDate><dc:creator>stuart.steedman</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>I have tried two variations, but both give the same problem:    Dim arr As New ArrayList        arr.Add("636")        arr.Add("437")        arr.Add("618")        arr.Add("568")     Dts.Variables("User::VStations").Value = arrand      Dim arr As Array        arr = "636, 437, 618, 568".Split(",")     Dts.Variables("User::VStations").Value = arr</description><pubDate>Wed, 30 May 2012 09:04:03 GMT</pubDate><dc:creator>george.allen</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Sounds like you are ignoring the zeroeth element of the array.  Does your code for populating the array look something like this?:Dim MyArray(4)MyArray(1) = "One"MyArray(2) = "Two"MyArray(3) = "Three"MyArray(4) = "Four"So, you also have the MyArray(0) value...</description><pubDate>Wed, 30 May 2012 08:21:46 GMT</pubDate><dc:creator>stuart.steedman</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Working in 2008 R2: I attempted this setup, excpet in my case I was creating an array of strings which drive a query to read data from a database to build a new dataset.  My problem is that I pass 4 values into the array and start the routine by the For Each Loop processes the 4 iterations and then keeps on goign to a fifth iteration with a vlaue of 0.  Why?</description><pubDate>Wed, 30 May 2012 08:03:20 GMT</pubDate><dc:creator>george.allen</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Hi,Try checking out this article:http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/64014/its a little cryptic but you have actually use the ADO Enumerator to do what you are trying to accomplish.</description><pubDate>Wed, 18 May 2011 13:22:39 GMT</pubDate><dc:creator>channa wijesinghe</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[quote][b]willtwc (12/22/2010)[/b][hr]Use ADO instead.[/quote]Why?:blink:</description><pubDate>Wed, 22 Dec 2010 22:27:41 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Use ADO instead.</description><pubDate>Wed, 22 Dec 2010 15:56:13 GMT</pubDate><dc:creator>willtwc</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[quote][b]Phil Parkin (12/23/2009)[/b][hr][quote][b]Jeff Moden (12/22/2009)[/b][hr]Heh... I probably wouldn't use SSIS for such a thing.  I damned sure wouldn't use a script for this. T-SQL would do the job just fine.[/quote]So ... what would you use SSIS for Jeff? :-)[/quote]Heh... (counting my lucky stars as I speak)... "nothing" is all I can come up with, so far.</description><pubDate>Wed, 22 Dec 2010 09:35:53 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>- Set up a variable to hold the Array.  This must be a System.Object type variable.- Set up a variable to hold the current array value.  The must be a String.- Set the array up like this;Dim sourceTabs() As String    sourceTabs = "Sheet1$,Sheet2$".Split(",")- Set the loop up using the above variables- Voila!(The example above was used to iterate through a fixed list of Excel tabs which were then used as data sources.)The crucial part was to set up the object as an Array, rather than an ArrayList.Stu</description><pubDate>Tue, 21 Dec 2010 07:32:54 GMT</pubDate><dc:creator>stuart.x.steedman</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[quote][b]sabyasm (12/22/2009)[/b][hr][font="Comic Sans MS"]^^ Correct.Also you wouldn't want to hardcode something like database names  in the script task -as new databases may be added or dropped.. :cool:[/font][/quote]Hi Sabyasm,Good point. I'm not retreving and hardcoding the database names. I'm just gettng the names of the feeds we do run at work and those are configured by our team :-)Thanks,Prasad</description><pubDate>Wed, 23 Dec 2009 07:35:29 GMT</pubDate><dc:creator>Prasad Boppana</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[quote][b]Jeff Moden (12/22/2009)[/b][hr]Heh... I probably wouldn't use SSIS for such a thing.  I damned sure wouldn't use a script for this.   T-SQL would do the job just fine.[/quote]Hi Jeff,I'm new to SSIS and I'm trying to see how I can use the foreach loop container in big scheme of things. This is a part of the package and package does have multiple data flow tasks in it besides the foreach loop container.Thanks,Prasad</description><pubDate>Wed, 23 Dec 2009 07:31:18 GMT</pubDate><dc:creator>Prasad Boppana</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[quote][b]Jeff Moden (12/22/2009)[/b][hr]Heh... I probably wouldn't use SSIS for such a thing.  I damned sure wouldn't use a script for this. T-SQL would do the job just fine.[/quote]So ... what would you use SSIS for Jeff? :-)</description><pubDate>Wed, 23 Dec 2009 00:05:33 GMT</pubDate><dc:creator>Phil Parkin</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Heh... I probably wouldn't use SSIS for such a thing.  I damned sure wouldn't use a script for this.   T-SQL would do the job just fine.</description><pubDate>Tue, 22 Dec 2009 20:14:06 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[font="Comic Sans MS"]^^ Correct.Also you wouldn't want to hardcode something like database names  in the script task -as new databases may be added or dropped.. :cool:[/font]</description><pubDate>Tue, 22 Dec 2009 11:37:34 GMT</pubDate><dc:creator>sabyasm</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Firstly I wouldnt use a Script task they ar quite slow and can have problems on 64bit machines if they arnt precompiled. I would use an Execute SQL task to get the data set and assign it to a Variable of Type Object. You can then use the For Each ADO enumerator to parse the Each element of Object Variable into a New Variable using the Variable Mapping section of the Loop Column 1 in the record set = Index 0 on the mappnig (Column 2= 1, and so on).</description><pubDate>Tue, 22 Dec 2009 10:16:21 GMT</pubDate><dc:creator>Jason-299789</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>That worked for me. I was able to figure out where I'm doing wrong.Thanks,Prasad</description><pubDate>Tue, 22 Dec 2009 09:37:18 GMT</pubDate><dc:creator>Prasad Boppana</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[quote][b]Jason Lees-299789 (12/22/2009)[/b][hr]Like Jeff, I'm not sure what it is you are trying to do.what is the purpose of the package? Is it to parse through a list of files?, to loop through a dataset?[/quote]I need to get a list of Names from the database and  use the list it in multiple tasks of the package. So I'm getting the names from the database and storing them in to a array list. The array list is stored in to a variable of System.Object. This will avoid the trips to the database to get the names every time I need them. I'm trying to figure out how to read the names from the Variable(User::Collection) using the ForEach From Variable Enumerator.Hope this helps.</description><pubDate>Tue, 22 Dec 2009 09:36:29 GMT</pubDate><dc:creator>Prasad Boppana</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[quote][b]sabyasm (12/22/2009)[/b][hr][quote]what is the purpose of the package? Is it to parse through a list of files?, to loop through a dataset? [/quote][font="Comic Sans MS"]You already asked :-P ...I was more curious and tried to help on why it wasn't working - rather than why he is using this approach..[/font][/quote]Touche....:-D</description><pubDate>Tue, 22 Dec 2009 09:08:52 GMT</pubDate><dc:creator>Jason-299789</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[quote]what is the purpose of the package? Is it to parse through a list of files?, to loop through a dataset? [/quote][font="Comic Sans MS"]You already asked :-P ...I was more curious and tried to help on why it wasn't working - rather than why he is using this approach..[/font]</description><pubDate>Tue, 22 Dec 2009 09:00:36 GMT</pubDate><dc:creator>sabyasm</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[quote][b]sabyasm (12/22/2009)[/b][hr][font="Comic Sans MS"]The only additional thing I did was to define a variable user::fileJustFound (string).On for each loop container -&amp;gt; variable mapping -&amp;gt; mapped user::fileJustFound as 0 (the only one variable)Then used a simple file system task to delete the file with name = user::fileJustFound....It looped through successfully and deleted files. Wondering if you are missing this part of mapping the variable appropriately.[/font][/quote]I would ask whats the point of using the Script Task if its a simple File directory parser, why not simply use the built in file Enumerator thats provided in the Task. </description><pubDate>Tue, 22 Dec 2009 08:57:18 GMT</pubDate><dc:creator>Jason-299789</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[font="Comic Sans MS"]The only additional thing I did was to define a variable user::fileJustFound (string).On for each loop container -&amp;gt; variable mapping -&amp;gt; mapped user::fileJustFound as 0 (the only one variable)Then used a simple file system task to delete the file with name = user::fileJustFound....It looped through successfully and deleted files. Wondering if you are missing this part of mapping the variable appropriately.[/font]</description><pubDate>Tue, 22 Dec 2009 08:49:53 GMT</pubDate><dc:creator>sabyasm</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>[font="Comic Sans MS"]Works fine for me. How are you trying to access the variable from the object? Did you define another variable and mapped in for each loop?[/font]</description><pubDate>Tue, 22 Dec 2009 08:46:05 GMT</pubDate><dc:creator>sabyasm</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Like Jeff, I'm not sure what it is you are trying to do.what is the purpose of the package? Is it to parse through a list of files?, to loop through a dataset?</description><pubDate>Tue, 22 Dec 2009 08:38:17 GMT</pubDate><dc:creator>Jason-299789</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Hi,I'm trying to use "ForEach From Variable" Enumerator. In the foreach loop, I'm able to read only the first item from the collection.How can I access all the items in the collection?Thanks,</description><pubDate>Tue, 22 Dec 2009 07:59:03 GMT</pubDate><dc:creator>Prasad Boppana</dc:creator></item><item><title>RE: SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>In plain English, what is it that you're trying to do?</description><pubDate>Mon, 21 Dec 2009 18:07:06 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>SSIS - ForEach From Variable Enumerator</title><link>http://www.sqlservercentral.com/Forums/Topic837644-148-1.aspx</link><description>Hi,I'm using ForEach Loop container and selected "ForEach From Variable Enumerator" option. I created a variable of System.Object(User::Collection) and selected the "User::Collection" for Variable dropdown in Enumertaor configuration.I have a script task that populates the "User::Collection" variable. The code is listed belowPublic Sub Main()		'		' Add your code here        '                 Dim arr As New ArrayList                 arr.Add("D:\Tests\a.txt")                 arr.Add("D:\Tests\b.txt")                 Dts.Variables("User::Collection").Value = arr		Dts.TaskResult = Dts.Results.Success	End SubThe script task that populates the collection is connected to the foreach loop. In the foreach loop, there is a script task that reads the indexed value and displaying the value. I'm able to read only the first value and not all the other values in the collection. Any thoughts?Thanks in Advance</description><pubDate>Mon, 21 Dec 2009 16:25:57 GMT</pubDate><dc:creator>Prasad Boppana</dc:creator></item></channel></rss>