<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://beyondrelational.com/live/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>Search results matching tag 'Recordset Destination'</title><link>http://beyondrelational.com/live/search/SearchResults.aspx?a=1&amp;o=DateDescending&amp;tag=Recordset+Destination&amp;orTags=0</link><description>Search results matching tag 'Recordset Destination'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>SSIS–Dynamically set File Mask : FileSpec</title><link>http://beyondrelational.com/live/blogs/sudeep/archive/2010/09/28/ssis-dynamically-set-file-mask-filespec.aspx</link><pubDate>Tue, 28 Sep 2010 19:10:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:9199</guid><dc:creator>sudeep</dc:creator><description>&lt;p&gt;In the SSIS Forum I came across the following query and thought of writing a post on the same.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Can anyone give guidance on how to set the mask for a Foreach File Enumerator programmatically? I have a DB that has a list of masks. I am retrieving that into an ADO recordset. For each record I retrieve the value into a variable. I would like to look at a directory and copy all files that begin with the chars for each item in my recordset variable.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The solution I provide uses a Flat File to store the various file mask in stead of a Table as required in the above case.&lt;/p&gt;
&lt;pre class="brush: plain"&gt;b*.txt
a*.txt
d*
*z.xlsx&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="color:#f79646;"&gt;The above scenario could be broken into 3 parts:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the flat file and save the values to a object type variable. &lt;/li&gt;
&lt;li&gt;Loop through each row of the object variable(which contains the file masks). &lt;/li&gt;
&lt;li&gt;For each of the mask traverse the folder and copy/move(or any other operation you need) the files that match the current file mask. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="color:#f79646;"&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The input folder has the following files:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/InputFolder.png"&gt;&lt;img src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/InputFolder.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For the first part check my other blog post on &amp;ldquo;&lt;a target="_blank" href="http://beyondrelational.com/blogs/sudeep/archive/2010/09/09/loop-through-each-record-in-a-text-file-recordset-destination.aspx"&gt;Loop through each record in a text file&lt;/a&gt;&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Next you need to set up the 1st foreach loop which will iterate though each row in the object variable and save the file mask to the user variable &amp;quot;&lt;strong&gt;strFileMask&lt;/strong&gt;&amp;quot;.&lt;/p&gt;
&lt;p&gt;Put another Foreach loop inside the above foreach loop. containing a file system task to copy the file source file to destination location.&lt;/p&gt;
&lt;p&gt;While setting up this foreach loop set the enumerator to Foreach File Enumerator. In the expressions set FileSpec to the expression @[User::strFileMask] this will change the file mask as per the mask set by the previous foreach loop. In variable mapping map the variable set up another user variable strFileName to store the file path of the filtered file.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/FELC_5F00_Mask.png"&gt;&lt;img src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/FELC_5F00_Mask.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="color:#f79646;"&gt;Above is the basic setup that is required to to achieve our goal. &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now in the 2nd for each loop we may put any task that we need to use this settings. It could be a data flow task File System task or email task or any other task. I will be using a file system task to copy the file filtered based on the file mask set here and send those files to destination folder.&lt;/p&gt;
&lt;p&gt;Set up the file system task as shown below:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/FileSystem-Task.png"&gt;&lt;img src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/FileSystem-Task.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The connection used above for the destination has the expression set for the connection string as:&lt;/p&gt;
&lt;pre class="brush: plain"&gt;&amp;quot;I:\\SSIS\\BLOGS\\Dynamic File Mask\\Output\\&amp;quot;+REVERSE(SUBSTRING(REVERSE(@[User::strFileName]),1, FINDSTRING(REVERSE(@[User::strFileName]),&amp;quot;\\&amp;quot;,1)-1))&lt;/pre&gt;
&lt;p&gt;The package would look like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/Pkg.png"&gt;&lt;img src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/Pkg.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;On package execution the destination folder would have the following files:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/OutputFolder.png"&gt;&lt;img src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/OutputFolder.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The package(SSIS 2008) is available for download &lt;a target="_blank" href="http://beyondrelational.com/blogs/sudeep/archive/2010/02/16/sample-ssis-packages.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Let me know if you need any specific clarification.&lt;/p&gt;</description></item><item><title>Loop through each record in a text file : Recordset Destination</title><link>http://beyondrelational.com/live/blogs/sudeep/archive/2010/09/08/loop-through-each-record-in-a-text-file-recordset-destination.aspx</link><pubDate>Wed, 08 Sep 2010 19:43:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:8877</guid><dc:creator>sudeep</dc:creator><description>&lt;p&gt;In most ETL we use Foreach loop to iterate through each file in a folder or records fetched from a table. Now the question arises how do we use Foreach loop based on each record in a text file.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="color:#f79646;"&gt;Scenario&lt;/span&gt;&lt;/strong&gt;: We have a text file having 2 columns, one containing source file relative path and 2nd column having the destination file relative path. The objective is to fetch each file from the source folder that are there in the our text file and move them to destination based on the connections available in the text file on the same record.&lt;/p&gt;
&lt;h3&gt;Caution: Do NOT use this method to read each record in the file if it caontain data and try to emulate a cursor. Use a data flow task instead.&lt;/h3&gt;
&lt;p&gt;File Layout:&lt;/p&gt;
&lt;p&gt;InputFilePath,OutputFilePath &lt;br /&gt;\Input\Input1.txt,Output\Output1.txt &lt;br /&gt;\Input\Input2.txt,Output\Output2.txt &lt;br /&gt;\Input\Input3.txt,Output\Output3.txt&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="color:#f79646;"&gt;The overall package:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/Package.png"&gt;&lt;img border="0" src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/Package.png" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The first Data Flow Task(DFT) uses a Flat File &lt;span style="color:#333333;"&gt;Source to read the data&lt;/span&gt; and send it to an object type user variable. The Foreach loop consumes this object variable and iterates through each record in the object variable. In the foreach loop the variable are mapped to 2 string user variables one to store the source file relative path and the other to store the Destination file relative path. At the end of the package execution all the files mentioned in the 1st column of the text file needs to be moved to the destination based on the 2nd column value.&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#f79646;"&gt;&lt;strong&gt;Variables used in the package:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10.1pt;color:#000000;"&gt;&lt;strong&gt;obj&lt;/strong&gt;:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Object type variable to store the records from the text file as an object.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;strBaseFolder&lt;/strong&gt;: The base folder where all the other files and folder reside.(not necessary to have this inn case the source and destination locations are in different place)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;strInputFile:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/strong&gt;Store the relative file path of the source file. Details will be discussed when I talk about the Foreach Loop.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;strOutputFile:&amp;nbsp;&amp;nbsp; &lt;/strong&gt;Store the relative file path of the destination file. Details will be discussed when I talk about the Foreach Loop.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/variables.png"&gt;&lt;img border="0" src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/variables.png" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#f79646;"&gt;&lt;strong&gt;Connections used in the package:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10.1pt;color:#000000;"&gt;All the connection used are Flat File Connections&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10.1pt;color:#000000;"&gt;&lt;strong&gt;Connections:&lt;/strong&gt; It provides the connection to connect to the flat file having all the connections. The connection string is set by the expression &lt;strong&gt;&lt;span style="color:#c0504d;"&gt;@[User::strBaseFolder] + &amp;ldquo;\\Connections.txt&amp;rdquo;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10.1pt;color:#000000;"&gt;&lt;strong&gt;Input:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/strong&gt;It provides the connection to the input file which needs to be moved to the output file. The connection string is set by the expression &lt;strong&gt;&lt;span style="color:#c0504d;"&gt;@[User::strBaseFolder] + &amp;quot;\\&amp;quot; +&amp;nbsp; @[User::strInputFile]&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10.1pt;color:#000000;"&gt;&lt;strong&gt;Output:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/strong&gt;It provides the connection for the destination file. The connection string is set by the expression &lt;strong&gt;&lt;span style="color:#c0504d;"&gt;@[User::strBaseFolder] + &amp;quot;\\&amp;quot; +&amp;nbsp; @[User::strOutputFile]&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;span&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/connections.png"&gt;&lt;img border="0" src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/connections.png" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#f79646;"&gt;&lt;strong&gt;DFT1 settings:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/DFT.png"&gt;&lt;img border="0" src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/DFT.png" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the Flat file source we use a connection to read the text file as a comma separated file.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="color:#ff0000;background-color:#cccccc;"&gt;Recordset Destination:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Component Properties tab&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/recordset1.png"&gt;&lt;img border="0" src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/recordset1.png" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;span style="color:#ffffff;background-color:#666666;"&gt;Note: The variable obj is a user variable of object type.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In the Input Properties tab only check the columns you wish to sent to the object variable.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/recordset2.png"&gt;&lt;img border="0" src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/recordset2.png" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;No need to make any changes in the 3rd tab &amp;ldquo;Input and output properties&amp;rdquo;. We now have the obj variable which can be used in the foreach loop to iterate through each record.&lt;/strong&gt; The remaining logic is same as applied to any other foreach loop.&lt;/p&gt;
&lt;p&gt;Now we come to the &lt;strong&gt;&lt;span style="color:#f79646;"&gt;Foreach loop&lt;/span&gt;&lt;/strong&gt; and set it up. Set the enumerator to &amp;ldquo;&amp;quot;Foreach ADO Enumerator&amp;rdquo;. Select the ADO obj Source variable from the drop down box and set it to &amp;ldquo;User::obj&amp;rdquo; variable. The Enumerator mode is set to default &amp;ldquo;Rows in first table&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/FEL1.png"&gt;&lt;img border="0" src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/FEL1.png" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We now need to read the value present in each row and assign it to string variables to be consumed later. Add the user variables by selecting them from the drop down list the user variables. Set the index to 0 for the first column data and index to 2 for the 2nd column variable.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/FEL2.png"&gt;&lt;img border="0" src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/FEL2.png" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the DFT 2 we have a flat file source and a flat file destination. I have used no transforms in this scenario which you could include as per your requirement.&lt;/p&gt;
&lt;p&gt;The Flat file source uses the connection &amp;ldquo;&lt;strong&gt;Input&lt;/strong&gt;&amp;rdquo; while the destination uses the connection &amp;ldquo;&lt;strong&gt;Output&lt;/strong&gt;&amp;rdquo;mentioned earlier.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/DFT2.png"&gt;&lt;img border="0" src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/DFT2.png" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The package is ready for execution.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/Package-run.png"&gt;&lt;img border="0" src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/sudeep/Package-run.png" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have uploaded the package &lt;a target="_blank" href="https://docs.google.com/leaf?id=0B2Xid3EEt_ozZWY5Njg3MjEtZDYwMS00NjdhLTkzOTEtYThhMzQ2MTRiODQ4&amp;amp;sort=name&amp;amp;layout=list&amp;amp;num=50"&gt;&lt;strong&gt;Recordset&lt;/strong&gt;&lt;/a&gt; for you reference.&lt;/p&gt;</description></item></channel></rss>