<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://consultingblogs.emc.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SSIS Junkie : Foreach Loop</title><link>http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx</link><description>Tags: Foreach Loop</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP3 (Build: 20423.1)</generator><item><title>SSIS: Initialise variables the easy way</title><link>http://consultingblogs.emc.com/jamiethomson/archive/2008/09/09/ssis-initialise-variables-the-easy-way.aspx</link><pubDate>Tue, 09 Sep 2008 18:58:48 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:12493</guid><dc:creator>jamie.thomson</dc:creator><slash:comments>5</slash:comments><comments>http://consultingblogs.emc.com/jamiethomson/comments/12493.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/jamiethomson/commentrss.aspx?PostID=12493</wfw:commentRss><wfw:comment>http://consultingblogs.emc.com/jamiethomson/rsscomments.aspx?PostID=12493</wfw:comment><description>&lt;p&gt;Its possible that at some point when building SSIS packages that you will want to initialise a variable with some value at execution time and the most obvious way of doing this is to use a script task. That code would look something like the following:&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:7725985c-ec90-49bd-aa69-e09d9b813239" style="padding-right:0px;display:inline;padding-left:0px;float:none;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;&lt;pre style="background-color:White;overflow:auto;"&gt;&lt;div&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;Public&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;Sub&lt;/span&gt;&lt;span style="color:#000000;"&gt; Main()
        &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;Dim&lt;/span&gt;&lt;span style="color:#000000;"&gt; vars &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;As&lt;/span&gt;&lt;span style="color:#000000;"&gt; Variables
        Dts.VariableDispenser.LockForWrite(&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;User::Variable&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)
        Dts.VariableDispenser.GetVariables(vars)
        vars(&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;User::Variable&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;).Value &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Some silly string&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
        vars.Unlock()

        Dts.TaskResult &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; ScriptResults.Success
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;End Sub&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Not everyone likes writing code mind you so here's a nifty little trick you could try instead. The ForEach Loop uses enumerators to define the collection that needs looping over; one of those enumerators is the ForEach Item enumerator which simply allows you to type in values at design-time that will be looped over at execution time. Very simple stuff indeed. Here you can see that I've set up a ForEach Loop accordingly:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.conchango.com/blogs/jamiethomson/WindowsLiveWriter/SSISInitialiseavariabletheeasyway_AB82/image_2.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="563" alt="image" src="http://blogs.conchango.com/blogs/jamiethomson/WindowsLiveWriter/SSISInitialiseavariabletheeasyway_AB82/image_thumb.png" width="587" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I've defined a 1-column, 1-row collection containing a single value &amp;quot;Some Silly String&amp;quot;. On the &lt;strong&gt;Variable Mappings&lt;/strong&gt; tab I just have to assign that value into a variable like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.conchango.com/blogs/jamiethomson/WindowsLiveWriter/SSISInitialiseavariabletheeasyway_AB82/image_4.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="561" alt="image" src="http://blogs.conchango.com/blogs/jamiethomson/WindowsLiveWriter/SSISInitialiseavariabletheeasyway_AB82/image_thumb_1.png" width="586" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Errr and that's it, the variable &lt;font face="Courier New"&gt;User::Variable&lt;/font&gt; is initialised with the value &amp;quot;Some Silly String&amp;quot;. Admittedly I can't really think of a practical use for this (can you think of one?) but at least it introduces the ForEach Item Enumerator, a little known feature of SSIS. Truthfully I've only written this to kill some time on a long car journey but hopefully it proves useful to someone out there, let me know if so. Until next time...&lt;/p&gt;

&lt;p&gt;-Jamie&lt;/p&gt;&lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=12493" width="1" height="1"&gt;</description><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SQL+Server+Integration+Services/default.aspx">SQL Server Integration Services</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Variables/default.aspx">Variables</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx">Foreach Loop</category></item><item><title>SSIS: Deleting a group of files</title><link>http://consultingblogs.emc.com/jamiethomson/archive/2008/04/17/ssis-deleting-a-group-of-files.aspx</link><pubDate>Thu, 17 Apr 2008 21:38:35 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:10696</guid><dc:creator>jamie.thomson</dc:creator><slash:comments>3</slash:comments><comments>http://consultingblogs.emc.com/jamiethomson/comments/10696.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/jamiethomson/commentrss.aspx?PostID=10696</wfw:commentRss><wfw:comment>http://consultingblogs.emc.com/jamiethomson/rsscomments.aspx?PostID=10696</wfw:comment><description>&lt;p&gt;A question I quite often see on the &lt;a href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=80&amp;amp;SiteID=1" target="_blank"&gt;SSIS forum&lt;/a&gt; is:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;Is there a way to delete a group of files within a directory? ie: I want to delete all files in directorty c:\logs\*.txt &lt;p&gt;(&lt;a title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3196521&amp;amp;SiteID=1" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3196521&amp;amp;SiteID=1"&gt;http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3196521&amp;amp;SiteID=1&lt;/a&gt;)&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Well its actually quite easy, you just need&amp;nbsp; ForEach Loop container and the FileSystem Task. Here's how you set up the ForEach Loop container: &lt;p&gt;In the 'Collection' tab you need to specify the enumerator, the folder from which to delete, and a fie mask to specify the files that you want to delete. &lt;p&gt;&lt;a href="http://blogs.conchango.com/blogs/jamiethomson/WindowsLiveWriter/SSISDeletingagroupoffiles_13480/image_2.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="560" alt="image" src="http://blogs.conchango.com/blogs/jamiethomson/WindowsLiveWriter/SSISDeletingagroupoffiles_13480/image_thumb.png" width="586" border="0"&gt;&lt;/a&gt;  &lt;p&gt;In the Variable Mappings tab you need to store the enumerated filename in a pre-created variable. The index will be 0 in this case because we are only interested in the file name which gets returned in the first column of the zero-based enumeration. &lt;p&gt;&lt;a href="http://blogs.conchango.com/blogs/jamiethomson/WindowsLiveWriter/SSISDeletingagroupoffiles_13480/image_4.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="545" alt="image" src="http://blogs.conchango.com/blogs/jamiethomson/WindowsLiveWriter/SSISDeletingagroupoffiles_13480/image_thumb_1.png" width="582" border="0"&gt;&lt;/a&gt;  &lt;p&gt;&amp;nbsp; &lt;p&gt;After that we have the simple task of wiring up the File System task that we do like so: &lt;p&gt;&lt;a href="http://blogs.conchango.com/blogs/jamiethomson/WindowsLiveWriter/SSISDeletingagroupoffiles_13480/image_10.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="545" alt="image" src="http://blogs.conchango.com/blogs/jamiethomson/WindowsLiveWriter/SSISDeletingagroupoffiles_13480/image_thumb_4.png" width="582" border="0"&gt;&lt;/a&gt;  &lt;p&gt;Note that we have used the variable "[User::FileName] that we populated using the ForEach Lloop container. &lt;p&gt;&amp;nbsp; &lt;p&gt;And that is pretty much it. Very simple indeed when you know how. I have made a demo package available here: &lt;p&gt;&lt;iframe style="border-right:#dde5e9 1px solid;padding-right:0px;border-top:#dde5e9 1px solid;padding-left:0px;padding-bottom:0px;margin:3px;border-left:#dde5e9 1px solid;width:240px;padding-top:0px;border-bottom:#dde5e9 1px solid;height:66px;background-color:#ffffff;" src="http://cid-550f681dad532637.skydrive.live.com/embedrowdetail.aspx/Public/BlogShare/20080417/DeleteFilesInAFolder.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt; &lt;p&gt;-Jamie &lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=10696" width="1" height="1"&gt;</description><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SQL+Server+Integration+Services/default.aspx">SQL Server Integration Services</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx">Foreach Loop</category></item><item><title>SSIS: Put a package to sleep</title><link>http://consultingblogs.emc.com/jamiethomson/archive/2006/10/23/SSIS_3A00_-Put-a-package-to-sleep.aspx</link><pubDate>Mon, 23 Oct 2006 21:28:00 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:4952</guid><dc:creator>jamie.thomson</dc:creator><slash:comments>14</slash:comments><comments>http://consultingblogs.emc.com/jamiethomson/comments/4952.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/jamiethomson/commentrss.aspx?PostID=4952</wfw:commentRss><wfw:comment>http://consultingblogs.emc.com/jamiethomson/rsscomments.aspx?PostID=4952</wfw:comment><description>&lt;p&gt;A question was &lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=850959&amp;amp;SiteID=1" title="How to put a package to sleep?"&gt;recently asked&lt;/a&gt; on the SSIS forum about how you can put a package &amp;quot;to sleep&amp;quot;. In other words, pause execution for a defined length of time.&lt;/p&gt;&lt;p&gt;It was suggested to use a script task to do this. That would definately work but there is&amp;nbsp;actually a much easier way -&amp;nbsp;use an empty For Loop. Here&amp;#39;s a screenshot showing how to set it up.&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.conchango.com/photos/conchango_bloggers/images/5008/original.aspx" target="_blank"&gt;&lt;img border="0" height="544" src="http://blogs.conchango.com/photos/conchango_bloggers/images/5008/original.aspx" width="796" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;As you can see, all you need to do is set the EvalExpression property. It really is that easy. The expression here:&lt;/p&gt;&lt;p&gt;&lt;font color="#ff0000" face="Courier"&gt;DATEADD( &amp;quot;ss&amp;quot;, 10, @[System::ContainerStartTime]&amp;nbsp; ) &amp;gt;&amp;nbsp; GETDATE()&amp;nbsp;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;will pause the package for ten seconds. It works by looping until the time that it started looping plus ten seconds is less than the current time. Very simple indeed.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;One thing to be aware of in regards to this. In the current build of SSIS (SP1) there is a small bug that you should be aware of when using the For Loop or ForEach Loop. Each iteration of the For Loop or ForEach loop hangs onto a bit of memory - in other words there is a small memory leak. Hence if you loop enough times there is a miniscule possibility that you could get an out of memory exception. This bug has been fixed in SP2.&lt;/p&gt;&lt;p&gt;This bug&amp;nbsp;information comes from Travis Maddox.&amp;nbsp;who was running&amp;nbsp;a process in an infinite loop. On each loop iteration he was processing a&amp;nbsp;100k file (approximate size).&amp;nbsp;The steps outlined above for putting a package to sleep should not result in an infinite loop unless you code it up wrongly. The point being that it would take a huge processing requirement for you to encounter this bug so in all but the most extreme circumstances it really isn&amp;#39;t anything to worry about when you are building a &amp;quot;sleep&amp;quot; For Loop that doesn&amp;#39;t actually process any data..&lt;/p&gt;&lt;p&gt;My thanks go to Travis for this information.&lt;/p&gt;&lt;p&gt;-Jamie&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;UPDATE 2006-11-02: I neglected to check this out properly and I should make you aware that this technique may send your CPU utilization sailing a little close to the edge. Make sure you check out CPU util before you fully employ this technique.&lt;/p&gt;&lt;p&gt;Thanks to Darren Gosbell (and a couple of others) for pulling me up on this. And I apologise for not checking this out fully first. A lesson learnt methinks.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=4952" width="1" height="1"&gt;</description><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SQL+Server+Integration+Services/default.aspx">SQL Server Integration Services</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx">Foreach Loop</category></item><item><title>SSIS: Processing data from multiple files all at once</title><link>http://consultingblogs.emc.com/jamiethomson/archive/2006/10/14/SSIS_3A00_-Processing-data-from-multiple-files-all-at-once.aspx</link><pubDate>Sat, 14 Oct 2006 16:54:00 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:4631</guid><dc:creator>jamie.thomson</dc:creator><slash:comments>3</slash:comments><comments>http://consultingblogs.emc.com/jamiethomson/comments/4631.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/jamiethomson/commentrss.aspx?PostID=4631</wfw:commentRss><wfw:comment>http://consultingblogs.emc.com/jamiethomson/rsscomments.aspx?PostID=4631</wfw:comment><description>&lt;p&gt;Quite often you may want to process data from multiple files all at the same time. There are a number of options available to you if you want to do this.&lt;/p&gt;&lt;p&gt;1.&amp;nbsp;Have a seperate source adapter for each file and&amp;nbsp;amalgamate them together with the &lt;strong&gt;Union All&lt;/strong&gt; component.&lt;br /&gt;Advantages of this approach: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;This works well&amp;nbsp;if the files are of differing formats&lt;/li&gt;&lt;li&gt;You only have one executable in order to do everything&lt;/li&gt;&lt;/ul&gt;Disadvantages: &lt;ul&gt;&lt;li&gt;This does not work if the number of files differs each time&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;2. &lt;a href="http://blogs.conchango.com/jamiethomson/archive/2005/05/30/1489.aspx"&gt;Loop over the files in a Foreach loop&lt;/a&gt; and &lt;a href="http://blogs.conchango.com/jamiethomson/archive/2006/06/22/4116.aspx" title="Append to a raw file"&gt;append to a raw file&lt;/a&gt;. Then, process all data together in a&amp;nbsp;seperate data flow.&lt;br /&gt;Advantages: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;You can re-use data-flows for files of the same format&lt;/li&gt;&lt;li&gt;Works regardless of the number of files&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Disadvantages&lt;/p&gt;&lt;ul&gt;&lt;li&gt;You have more executables in your package&lt;/li&gt;&lt;li&gt;You will need to build control-flow logic to handle differing formats or else have some clever logic in your data-flow inside the Foreach loop&lt;/li&gt;&lt;li&gt;You need to stage the data (in the raw file)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;3. Use a &lt;a href="http://msdn2.microsoft.com/en-us/library/ms137830.aspx" title="Multiple Flat Files Connection Manager "&gt;MULTIFLATFILE connection manager&lt;/a&gt;&lt;br /&gt;Advantages &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Only one executable in your package&lt;/li&gt;&lt;li&gt;One set of logic if all files are of the same format&lt;/li&gt;&lt;li&gt;Works regardless of the number of files&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Disadvantages&lt;/p&gt;&lt;ul&gt;&lt;li&gt;You need some clever logic in your data-flow to handle&amp;nbsp;differing file formats&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Its clear that you choice depends on your circumstances so given that I don&amp;#39;t know your circumstances I won&amp;#39;t make a recommendation.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;-Jamie&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=4631" width="1" height="1"&gt;</description><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SQL+Server+Integration+Services/default.aspx">SQL Server Integration Services</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/raw+files/default.aspx">raw files</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Dataflow+Task/default.aspx">Dataflow Task</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx">Foreach Loop</category></item><item><title>SSIS: Expressions on ForEach enumerators</title><link>http://consultingblogs.emc.com/jamiethomson/archive/2006/10/13/SSIS_3A00_-Expressions-on-ForEach-enumerators.aspx</link><pubDate>Fri, 13 Oct 2006 21:35:00 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:4621</guid><dc:creator>jamie.thomson</dc:creator><slash:comments>29</slash:comments><comments>http://consultingblogs.emc.com/jamiethomson/comments/4621.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/jamiethomson/commentrss.aspx?PostID=4621</wfw:commentRss><wfw:comment>http://consultingblogs.emc.com/jamiethomson/rsscomments.aspx?PostID=4621</wfw:comment><description>&lt;p&gt;I&amp;#39;ve noticed a few people on the &lt;a href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=80&amp;amp;SiteID=1"&gt;SSIS forum&lt;/a&gt; lately asking about expressions on the Foreach Loop. They are aware that its possible to set expressions on properties of the Foreach container but are flummoxed when it comes to setting&amp;nbsp;expressions on the properties of the enumerators themselves. That&amp;#39;s understandable because the properties of the chosen enumerator are not available from the &amp;quot;Property Expressions Editor&amp;quot; on the &amp;quot;Expressions&amp;quot; tab of the &amp;quot;Foreach Loop Editor&amp;quot;&amp;nbsp; (which is where they usually appear). You can see that here:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.conchango.com/photos/conchango_bloggers/images/4624/original.aspx" target="_blank"&gt;&lt;img border="0" height="578" src="http://blogs.conchango.com/photos/conchango_bloggers/images/4624/original.aspx" width="969" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;All is not lost however. There&amp;#39;s a seperate route into expressions on enumerator properties via the &amp;quot;Collection&amp;quot; tab of the &amp;quot;Foreach Loop Editor&amp;quot;. I&amp;#39;ve highlighted that on the next screenshot that shows properties being set on the &lt;strong&gt;Foreach File Enumerator&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.conchango.com/photos/conchango_bloggers/images/4625/original.aspx" target="_blank"&gt;&lt;img border="0" height="594" src="http://blogs.conchango.com/photos/conchango_bloggers/images/4625/original.aspx" width="1080" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Note the &amp;quot;Expressions&amp;quot; section on the &amp;quot;Collection&amp;quot; tab. That&amp;#39;s the bit you&amp;#39;re interested in.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Dead easy when you know where to find it! I must admit it took me a while&amp;nbsp;until I discovered&amp;nbsp;it.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;-Jamie&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=4621" width="1" height="1"&gt;</description><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SQL+Server+Integration+Services/default.aspx">SQL Server Integration Services</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Expressions/default.aspx">Expressions</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx">Foreach Loop</category></item><item><title>SSIS: Append to a raw file</title><link>http://consultingblogs.emc.com/jamiethomson/archive/2006/06/22/SSIS_3A00_-Append-to-a-raw-file.aspx</link><pubDate>Thu, 22 Jun 2006 22:42:00 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:4116</guid><dc:creator>jamie.thomson</dc:creator><slash:comments>3</slash:comments><comments>http://consultingblogs.emc.com/jamiethomson/comments/4116.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/jamiethomson/commentrss.aspx?PostID=4116</wfw:commentRss><wfw:comment>http://consultingblogs.emc.com/jamiethomson/rsscomments.aspx?PostID=4116</wfw:comment><description>&lt;P&gt;I have just arrived home from an excellent BI-flavoured meeting of &lt;A href="http://sqlblogcasts.com/blogs/tonyrogerson/"&gt;Tony Rogerson's&lt;/A&gt; &lt;A href="http://www.sqlserverfaq.com/"&gt;UK SQL Server User Group&lt;/A&gt;. Aside from some great content the thing I love about these events is the change to meet up with people from around the BI community - people that I've met both in person and online in the past few years.&lt;BR&gt;So Rastko Petrovic, Mat Stephen, &lt;A href="http://www.sqljunkies.com/WebLog/simons/default.aspx"&gt;Simon Sabin&lt;/A&gt;, Tony, Sanjay Nayyar...great to see you guys again. To &lt;A href="http://cwebbbi.spaces.msn.com/PersonalSpace.aspx"&gt;Chris Webb&lt;/A&gt;, &lt;A href="http://tsutha.blogspot.com/"&gt;Sutha&amp;nbsp;Thiru&lt;/A&gt;&amp;nbsp;and &lt;A href="http://www.markhill.org/blog/"&gt;Mark Hill&lt;/A&gt;...glad to finally put some faces to your names - I just wish I'd had more of a chance to have a natter with you guys!&lt;/P&gt;
&lt;P&gt;Chris opened the evening by giving a great demo of some of the new features in MDX. That was really valuable to me due to the work I am currently undertaking in my day-to-day role. MDX Scripts are going to relieve some of my headaches I'm sure!&lt;/P&gt;
&lt;P&gt;Mark followed by talking through his experiences of implementing a SSAS solution for a 2 billion row fact table. It was really valuable to hear some first-hand experience of the pain that he and Rastko have gone through on their current project and I'll definately be applying some of those learnings to what I'm doing now.&lt;BR&gt;I was slightly disappointed to hear some criticism of SSIS's performance against none-SQL Server data sources but I can't argue with hard facts and Mark raised some serious concerns that I hope the SSIS team are going to take on board.&lt;/P&gt;
&lt;P&gt;Simon followed up with a whistlestop demo of how to load and analyse unstructured ASP.Net exception files using SSIS. I love Simon's style of presenting. He comes across as being utterly unprepared (I'm sure he won't mind me saying that) and yet somehow manages to get his point across through sheer tenacity, wit and crazy exuberance.&lt;/P&gt;
&lt;P&gt;Part of Simon's demo was showing how to loop over a set of files using a ForEach Loop and append the results to a raw file so that the full set of data from all source files can be processed as a whole. In order to do this Simon showed how it is necassary to, prior to the ForEach Loop execution, create an empty raw file with the same metadata as the raw file required to load the data into. His method of doing this was very simple - use a script component. All well and good.&lt;/P&gt;
&lt;P&gt;I made a slight fool of myself by piping up in the middle of Simon's presentation that creating the empty raw file manually like that wasn't necassary - it is possible to make SSIS create the raw file on the first iteration of the loop- but when he challenged me to prove it I couldn't remember how. I was sure it was possible though.&lt;/P&gt;
&lt;P&gt;Well, naturally, afterwards I went away to try and prove myself right and thankfully I'm not really as foolish as I might have first appeared. It IS possible to loop over files, creating the raw file on the first iteration and then appending to it thereafter. The trick is to set ValidateExternalMetadata=False on the raw file destination adapter as shown here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.conchango.com/photos/conchango_bloggers/images/4120/original.aspx" target=_blank&gt;&lt;IMG src="https://blogs.conchango.com/photos/conchango_bloggers/images/4120/original.aspx" border=0&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;If you want to see this for yourself then download a demo package from &lt;A href="https://blogs.conchango.com/jamiethomson/attachment/4116.ashx"&gt;here&lt;/A&gt;. There are no connection managers in the package so running it&amp;nbsp;will not&amp;nbsp;be a problem. Here's a screenshot of the control-flow:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.conchango.com/photos/conchango_bloggers/images/4118/original.aspx" target=_blank&gt;&lt;IMG src="https://blogs.conchango.com/photos/conchango_bloggers/images/4118/original.aspx" border=0&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The only thing you need to make sure of is that it has read-write access to C:\temp because that is where it creates the raw file. Here's a screenshot of the data-flow:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.conchango.com/photos/conchango_bloggers/images/4119/original.aspx" target=_blank&gt;&lt;IMG src="https://blogs.conchango.com/photos/conchango_bloggers/images/4119/original.aspx" border=0&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the upshot of this is:&lt;BR&gt;-You can append to a raw file within a ForEach loop&lt;BR&gt;-It is possible to configure the raw file destination so that on the first iteration of the ForEach loop the raw file will get created.&lt;/P&gt;
&lt;P&gt;Its an important point because being able to process data from multiple files all at once is an&amp;nbsp;common requirement. Simon himself gave a clear example of this by taking a LOOKUP component out of the ForEach loop so that it only had to execute&amp;nbsp; (and therefore cache all its data) once. Leaving it inside would be a major faux pas in terms of performance.&lt;/P&gt;
&lt;P&gt;So all in all a good night and thanks to Chris, Mark, Simon and Tony for that. And a lesson learnt for me - don't jump headlong&amp;nbsp;into&amp;nbsp;someone else's&amp;nbsp;demo unless you can back up what you are saying!&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;-Jamie&lt;BR&gt;&lt;/P&gt;&lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=4116" width="1" height="1"&gt;</description><enclosure url="http://consultingblogs.emc.com/jamiethomson/attachment/4116.ashx" length="25177" type="application/x-zip-compressed" /><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SQL+Server+Integration+Services/default.aspx">SQL Server Integration Services</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/raw+files/default.aspx">raw files</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx">Foreach Loop</category></item><item><title>SSIS Nugget: Setting expressions</title><link>http://consultingblogs.emc.com/jamiethomson/archive/2006/03/11/SSIS-Nugget_3A00_-Setting-expressions.aspx</link><pubDate>Sat, 11 Mar 2006 09:24:00 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:3063</guid><dc:creator>jamie.thomson</dc:creator><slash:comments>30</slash:comments><comments>http://consultingblogs.emc.com/jamiethomson/comments/3063.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/jamiethomson/commentrss.aspx?PostID=3063</wfw:commentRss><wfw:comment>http://consultingblogs.emc.com/jamiethomson/rsscomments.aspx?PostID=3063</wfw:comment><description>&lt;P&gt;Whilst reading posts on the &lt;A href="http://forums.microsoft.com/msdn/showforum.aspx?forumid=80&amp;amp;siteid=1"&gt;SSIS forum&lt;/A&gt; of late it has become evident that people are unaware of the power that expressions can provide within an SSIS package. This is understandable - alot of people are starting to&amp;nbsp;use SSIS now but expressions aren't the most obvious feature.&lt;/P&gt;
&lt;P&gt;So what are they? Well the most generic explanation is that expressions allow your packages to be dynamic by setting properties of objects at runtime. What are they used for? Well there are a number of scenarios, the most common being:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Dynamically setting the&amp;nbsp;connection string&amp;nbsp;of external connections 
&lt;LI&gt;Conditional precedence constraints 
&lt;LI&gt;Setting the location of raw files 
&lt;LI&gt;An alternative to parameterised SQL statements in the Execute SQL Task or a source adapter&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The reason that expressions aren't the most visually obvious feature is they're usually hidden away in the properties pane. Lets demonstrate that in one of the scenarios already mentioned - dynamically setting the connection string of external connections.&lt;/P&gt;
&lt;P&gt;Imagine the following scenario:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You have a data-flow that loads data from a&amp;nbsp;CSV file. 
&lt;LI&gt;That data-flow is within a ForEach loop that iterates over a collection of CSV files. 
&lt;LI&gt;The ForEach Loop populates a variable with the name and location of&amp;nbsp;the file&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;In other words your package looks something like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG height=469 alt=20060311PackageScr.JPG src="http://blogs.conchango.com/Admin/ImageGallery/blogs.conchango.com/jamie.thomson/20060311PackageScr.JPG" width=372 border=1&gt;&lt;/P&gt;
&lt;P&gt;On each loop iteration @[FileNameAndLocation] will, not surprisingly, store the name and location of the current file.&lt;/P&gt;
&lt;P&gt;Now, we need to make sure that the data-flow is going to process that file. We do that by dynamically setting the ConnectionString property of "FlatFileConnectionManager" using an expression. To do that select "FlatFileConnectionManager" and press F4. The properties pane will appear in which you will be able to see the entry point to the connection manager's expression collection:&lt;/P&gt;
&lt;P&gt;&lt;IMG height=469 alt=20060311Properties.JPG src="http://blogs.conchango.com/Admin/ImageGallery/blogs.conchango.com/jamie.thomson/20060311Properties.JPG" width=353 border=1&gt;&lt;/P&gt;
&lt;P&gt;Clicking the ellipsis will display the Property Expressions Editor dialog from which we select the ConnectionString property.&lt;/P&gt;
&lt;P&gt;&lt;IMG height=348 alt=20060311PropertyExpressionsEditor.JPG src="http://blogs.conchango.com/Admin/ImageGallery/blogs.conchango.com/jamie.thomson/20060311PropertyExpressionsEditor.JPG" width=438 border=1&gt;&lt;/P&gt;
&lt;P&gt;Thereafter we go through to the Expression Editor which is where we set up an expression that will dynamically set the ConnectionString property. In this case we use the @[FileNameAndLocation] variable:&lt;/P&gt;
&lt;P&gt;&lt;IMG height=516 alt=20060311ExpressionEditor.JPG src="http://blogs.conchango.com/Admin/ImageGallery/blogs.conchango.com/jamie.thomson/20060311ExpressionEditor.JPG" width=575 border=1&gt;&lt;/P&gt;
&lt;P&gt;As you can see from the evaluated value, the ConnectionString property will be set to the name of the variable. This means that on every iteration of the ForEach loop the file that the "FlatFileConnectionManager" will be pointing to to the currently iterated file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is only one use of expressions but hopefully through this simple scenario we've demonstrated how expressions are set and how they can be used.&lt;/P&gt;
&lt;P&gt;Remember that expressions are not only available to be set on connection managers, they can be set on variables, task properties and precedence constraints as well. You'll find that as you begin to build ever more complicated solutions you will start to use expressions more and more.&lt;/P&gt;
&lt;P&gt;-Jamie&lt;/P&gt;&lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=3063" width="1" height="1"&gt;</description><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SQL+Server+Integration+Services/default.aspx">SQL Server Integration Services</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/raw+files/default.aspx">raw files</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Expressions/default.aspx">Expressions</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx">Foreach Loop</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Nugget/default.aspx">Nugget</category></item><item><title>SSIS: Caching result sets for re-use in a ForEach loop</title><link>http://consultingblogs.emc.com/jamiethomson/archive/2006/02/20/SSIS_3A00_-Caching-result-sets-for-re_2D00_use-in-a-ForEach-loop.aspx</link><pubDate>Mon, 20 Feb 2006 17:08:00 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:2905</guid><dc:creator>jamie.thomson</dc:creator><slash:comments>1</slash:comments><comments>http://consultingblogs.emc.com/jamiethomson/comments/2905.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/jamiethomson/commentrss.aspx?PostID=2905</wfw:commentRss><wfw:comment>http://consultingblogs.emc.com/jamiethomson/rsscomments.aspx?PostID=2905</wfw:comment><description>&lt;P&gt;Peter (sorry, don't know your surname) made a very good comment here: &lt;a href="http://blogs.conchango.com/jamiethomson/archive/2006/02/20/2895.aspx#2903"&gt;http://blogs.conchango.com/jamiethomson/archive/2006/02/20/2895.aspx#2903&lt;/A&gt;&amp;nbsp;that data-flows in a ForEach loop carry out repeated SELECTs against a data source and it would be good to be able to cache that data rather than executing the same query over and over.&lt;/P&gt;
&lt;P&gt;Its a great point and one that I wholeheartedly endorse. Hopefully Peter has raised it at the &lt;A href="http://lab.msdn.microsoft.com/productfeedback/default.aspx"&gt;Feedback Centre&lt;/A&gt;. In the meantime, there is a workaround, of sorts, that can be used in certain situations.&lt;/P&gt;
&lt;P&gt;Peter's example talked of an OLE DB Source component that was being used in a MERGE JOIN component. He reasoned that seeing as that data wasn't changing for each iteration then the data could be cached somewhere. Well, how about populating a raw file with that data prior to the ForEach loop? That way the data source is only accessed once and the raw file can be used repeatedly as the source for the MERGE JOIN. Sure, its not quite as ideal as caching the data in memory but raw files are supremely fast and there is virtually no overhead in using them so speed should not be a problem. The main benefit here is of course that you don't put undue load on your RDBMS&amp;nbsp;but also,&amp;nbsp;it doesn't tie up memory resource.&lt;/P&gt;
&lt;P&gt;If the data cache is absolutely required to be held in memory then using an ADO recordset to store the data (as explained here: &lt;a href="http://blogs.conchango.com/jamiethomson/archive/2006/01/04/2540.aspx"&gt;http://blogs.conchango.com/jamiethomson/archive/2006/01/04/2540.aspx&lt;/A&gt;) could be&amp;nbsp;done instead.&lt;/P&gt;
&lt;P&gt;I find it useful to remember that there&amp;nbsp;is usually more than one way to achieve a desired action in SSIS. Explore the options that are available and you may find that better options exist that the obvious one - as exhibited here!&lt;/P&gt;
&lt;P&gt;-Jamie&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=2905" width="1" height="1"&gt;</description><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SQL+Server+Integration+Services/default.aspx">SQL Server Integration Services</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/raw+files/default.aspx">raw files</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/ole+db+source+adapter/default.aspx">ole db source adapter</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx">Foreach Loop</category></item><item><title>SSIS Nugget: Execute SQL Task into an object variable - Shred it with a Foreach loop</title><link>http://consultingblogs.emc.com/jamiethomson/archive/2005/07/04/SSIS-Nugget_3A00_-Execute-SQL-Task-into-an-object-variable-_2D00_-Shred-it-with-a-Foreach-loop.aspx</link><pubDate>Mon, 04 Jul 2005 08:55:00 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:1748</guid><dc:creator>jamie.thomson</dc:creator><slash:comments>43</slash:comments><comments>http://consultingblogs.emc.com/jamiethomson/comments/1748.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/jamiethomson/commentrss.aspx?PostID=1748</wfw:commentRss><wfw:comment>http://consultingblogs.emc.com/jamiethomson/rsscomments.aspx?PostID=1748</wfw:comment><description>&lt;P&gt;Here is the first in what will hopefully be a long series of postings in what I have colloquially called my &lt;a href="http://blogs.conchango.com/jamiethomson/archive/2005/07/04/1747.aspx"&gt;SSIS Nuggets&lt;/A&gt; series.&lt;/P&gt;
&lt;P&gt;I was reading a post this morning from Sam Bendayan in which he was pondering how to store a full result set returned from the &lt;A href="http://www.sqlis.com/default.aspx?58"&gt;Execute SQL Task&lt;/A&gt;. He had followed BOL (which according to Sam states that a Full Result Set should be stored in a variable of type String) but was getting errors.&lt;/P&gt;
&lt;P&gt;Well, that's not surprising really. BOL is wrong! A Full Result Set needs to be stored in variable of type Object. Typically you would then navigate through (sometimes called shred) this result set using a Foreach Loop (using the "Foreach ADO Enumerator"), carrying out whatever operations you wanted to on the way. In the example I have put together I simply output the contents of the current row of the result set using&amp;nbsp;the familar&amp;nbsp;message box.&lt;/P&gt;
&lt;P&gt;Here's a screenshot of this package:&lt;/P&gt;
&lt;P&gt;&lt;IMG height=359 alt=20050704_ExecuteSQLTask_nugget1.JPG src="http://blogs.conchango.com/Admin/ImageGallery/blogs.conchango.com/jamie.thomson/20050704_ExecuteSQLTask_nugget1.JPG" width=423 border=1&gt;&lt;/P&gt;
&lt;P&gt;Here's everything that the package does:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Populates a variable called User::FullResultSet using the Execute SQL Task. The data comes from the AdventureWorks.Production.Culture table (so you will need to have the AdventureWorks DB installed) 
&lt;LI&gt;Shreds the recordset using the Foreach loop and populates 2 variables: User::CultureID &amp;amp; User::Name with values from the current row of the result set 
&lt;LI&gt;Outputs the values of User::CultureID &amp;amp; User::Name in a message box&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Yes yes, I know that &lt;a href="http://blogs.conchango.com/admin/blogs/www.sqljunkies.com/weblog/knight_reign"&gt;Kirk&lt;/A&gt;, &lt;A href="http://www.sqlis.com/default.aspx?12"&gt;Allan &amp;amp; Darren&lt;/A&gt;, and myself have all previously posted similar examples of doing this, but one more can't hurt right?&lt;/P&gt;
&lt;P&gt;You can download the package from &lt;a href="http://blogs.conchango.com/Admin/ImageGallery/blogs.conchango.com/jamie.thomson/ExecuteSQL_full_result_set_into_a_variable.zip"&gt;here&lt;/A&gt;. All you need to do to run it is edit the connection manager to point at your SQL Server instance.&lt;/P&gt;
&lt;P&gt;-Jamie&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=1748" width="1" height="1"&gt;</description><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SQL+Server+Integration+Services/default.aspx">SQL Server Integration Services</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Execute+SQL+Task/default.aspx">Execute SQL Task</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx">Foreach Loop</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Nugget/default.aspx">Nugget</category></item><item><title>SSIS: Getting a value out of a file to use it in our package</title><link>http://consultingblogs.emc.com/jamiethomson/archive/2005/06/15/SSIS_3A00_-Getting-a-value-out-of-a-file-to-use-it-in-our-package.aspx</link><pubDate>Wed, 15 Jun 2005 21:21:00 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:1693</guid><dc:creator>jamie.thomson</dc:creator><slash:comments>4</slash:comments><comments>http://consultingblogs.emc.com/jamiethomson/comments/1693.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/jamiethomson/commentrss.aspx?PostID=1693</wfw:commentRss><wfw:comment>http://consultingblogs.emc.com/jamiethomson/rsscomments.aspx?PostID=1693</wfw:comment><description>&lt;P&gt;Someone recently asked on a newsgroup how they could grab hold of a value from a given field in the last row of a file. For example, in the file depicted below we would like to grab the value "Posh".&lt;/P&gt;&lt;IMG src="http://blogs.conchango.com/jamiethomson/files/20050615SourceFile.JPG" border=1&gt;&lt;/IMG&gt; 
&lt;P&gt;I figured this might be a fairly common requirement so figured I'd put something together to show how to do this. There's&amp;nbsp; probably a number of ways to accomplish this, but this is the way I would do it.&lt;/P&gt;
&lt;P&gt;The solution to this is two-fold:&lt;BR&gt;1) Populate a recordset with the contents of the file&lt;BR&gt;2) Iterate over the recordset using a Foreach loop, each time capturing the "Name" field into a string variable&lt;/P&gt;
&lt;P&gt;Once the Foreach loop has finished iterating the string variable will contain the value "Posh".&lt;/P&gt;
&lt;P&gt;Here's how it works.&lt;BR&gt;1. Define a variable to hold the recordset and a variable to hold the value extracted from the recordset&lt;BR&gt;&lt;IMG src="http://blogs.conchango.com/jamiethomson/files/20050615Variables.JPG"&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;2. Populate the recordset variable using the Recordset Destination component in a data-flow&lt;BR&gt;&lt;IMG src="http://blogs.conchango.com/jamiethomson/files/20050615DataFlow.JPG" border=1&gt;&lt;/P&gt;&lt;/IMG&gt;
&lt;P&gt;&lt;BR&gt;3. Define a Foreach loop with the "Foreach ADO Enumerator" and set the source variable to be the recordset variable we have just populated&lt;BR&gt;&lt;IMG src="http://blogs.conchango.com/jamiethomson/files/20050615ForeachCollection.JPG"&gt;&lt;/P&gt;&lt;/IMG&gt;
&lt;P&gt;&lt;BR&gt;4. In the Foreach loop, populate the string variable with a value from the current enumerated record.&lt;BR&gt;&lt;IMG src="http://blogs.conchango.com/jamiethomson/files/20050615ForeachVariableMappings.JPG"&gt;&lt;/P&gt;
&lt;P&gt;&lt;/IMG&gt;&lt;BR&gt;5. For demo-ing, stick on a script task that outputs the current value of our string variable.&lt;BR&gt;&lt;IMG src="http://blogs.conchango.com/jamiethomson/files/20050615ScriptTask.JPG"&gt;&lt;/IMG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's our simple control-flow. Note that there is nothing actually inside the foreach loop - its not needed.&lt;BR&gt;&lt;IMG src="http://blogs.conchango.com/jamiethomson/files/20050615ControlFlow.JPG" border=1&gt;&lt;/IMG&gt;&lt;/P&gt;
&lt;P&gt;Executing the package results in the following message box.&lt;BR&gt;&lt;IMG src="http://blogs.conchango.com/jamiethomson/files/20050615MsgBox.JPG"&gt;&lt;/IMG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;And its as easy as that! All we've done is capture the contents of the file into memory and then iterated over it until we get to the record we want.&lt;/P&gt;
&lt;P&gt;If you want to try this, download the package and source file from &lt;A href="http://blogs.conchango.com/jamiethomson/files/20050615LastRecordFromFile.zip"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;-Jamie&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=1693" width="1" height="1"&gt;</description><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SQL+Server+Integration+Services/default.aspx">SQL Server Integration Services</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Dataflow+Task/default.aspx">Dataflow Task</category><category domain="http://consultingblogs.emc.com/jamiethomson/archive/tags/Foreach+Loop/default.aspx">Foreach Loop</category></item></channel></rss>