<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.adatis.co.uk/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>Neil Dobner&amp;#39;s Blog</title><link>http://blogs.adatis.co.uk/blogs/neil/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP2 (Build: 20611.960)</generator><item><title>A Pattern To Load Data to Master Data Services via SSIS–Part 2</title><link>http://blogs.adatis.co.uk/blogs/neil/archive/2011/08/18/a-pattern-to-load-data-to-master-data-services-via-ssis-part-2.aspx</link><pubDate>Thu, 18 Aug 2011 16:26:30 GMT</pubDate><guid isPermaLink="false">8d7d37f8-4a66-4c95-9fba-293fa87607dc:9616</guid><dc:creator>Neil Dobner</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.adatis.co.uk/blogs/neil/rsscomments.aspx?PostID=9616</wfw:commentRss><comments>http://blogs.adatis.co.uk/blogs/neil/archive/2011/08/18/a-pattern-to-load-data-to-master-data-services-via-ssis-part-2.aspx#comments</comments><description>&lt;h5&gt;Introduction&lt;/h5&gt;  &lt;p&gt;This is the second part of a series of blog posts intended to show a way to load data in to MDS via SSIS. In &lt;a href="http://blogs.adatis.co.uk/blogs/neil/archive/2011/07/14/a-pattern-to-load-data-to-master-data-services-via-ssis.aspx"&gt;part 1&lt;/a&gt; we have loaded the staging tables with new members and attributes for several entities. In this blog post we are going to extend the SSIS package with tasks to move the data from the staging tables into the MDS Product model and validate these newly inserted members.&lt;/p&gt;  &lt;h5&gt;Completing The Solution&lt;/h5&gt;  &lt;p&gt;We need to move the data from the staging tables into the model. This is carried out by executing the MDS staging sweep process. To achieve this we need to add an Execute SQL Task to the control flow of our package. Rename the task – I’ve called mine ‘SQL – Sweep Stage’ and connect it up to the ‘DFL – Load Staging Tables’ task with a success constraint.&lt;/p&gt;  &lt;p&gt;On the General tab set the connection to MasterDataServices and the SQL Statement as follows:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;@ModelName   &lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;50&lt;span style="color:gray;"&gt;) = &lt;/span&gt;? 
&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;@UserName    &lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;50&lt;span style="color:gray;"&gt;) = &lt;/span&gt;?
&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;@User_ID     &lt;span style="color:blue;"&gt;INT 
DECLARE &lt;/span&gt;@Version_ID  &lt;span style="color:blue;"&gt;INT

SET &lt;/span&gt;@User_ID &lt;span style="color:gray;"&gt;=    (&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;ID  
                   &lt;span style="color:blue;"&gt;FROM  &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;tblUser u 
                   &lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;u&lt;span style="color:gray;"&gt;.&lt;/span&gt;UserName &lt;span style="color:gray;"&gt;= &lt;/span&gt;@UserName &lt;span style="color:gray;"&gt;) 

&lt;/span&gt;&lt;span style="color:blue;"&gt;SET &lt;/span&gt;@Version_ID &lt;span style="color:gray;"&gt;= (&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:magenta;"&gt;MAX&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;ID&lt;span style="color:gray;"&gt;)  
                   &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;viw_SYSTEM_SCHEMA_VERSION  
                   &lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;Model_Name &lt;span style="color:gray;"&gt;= &lt;/span&gt;@ModelName&lt;span style="color:gray;"&gt;)
                   

&lt;/span&gt;&lt;span style="color:blue;"&gt;EXECUTE &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;udpStagingSweep @User_ID&lt;span style="color:gray;"&gt;, &lt;/span&gt;@Version_ID&lt;span style="color:gray;"&gt;, &lt;/span&gt;1&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then add the Parameter mapping as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_7ECDD3A5.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_73A4495B.png" width="463" height="395" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s all there is to do to get our data into the model. However this process is asynchronous and before we can validate the model we need to know when the staging sweep has finished. &lt;/p&gt;

&lt;p&gt;Add a For Loop Container task to the control flow of the package and connect it up to the ‘SQL – Sweep Stage’ task with a success constraint. Rename the task – I’ve called mine ‘FLC – Wait Until Batch Completes’. Add an Execute SQL Task inside the loop container task and rename it. Mine is called ‘SQL – Get Staging Batch Status’. Change the connection to MasterDataServices, change the ResultSet property to ‘Single row’ and then add the following SQL script to the SQLStatement property:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;@Version_ID &lt;span style="color:blue;"&gt;INT

SET &lt;/span&gt;@Version_ID &lt;span style="color:gray;"&gt;= (&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:magenta;"&gt;MAX&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;ID&lt;span style="color:gray;"&gt;)  
                   &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;viw_SYSTEM_SCHEMA_VERSION  
                   &lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;Model_Name &lt;span style="color:gray;"&gt;= &lt;/span&gt;?&lt;span style="color:gray;"&gt;)

&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT TOP    &lt;/span&gt;1 Status_ID 
&lt;span style="color:blue;"&gt;FROM          &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;tblStgBatch 
&lt;span style="color:blue;"&gt;WHERE         &lt;/span&gt;Version_ID &lt;span style="color:gray;"&gt;= &lt;/span&gt;@Version_ID
&lt;span style="color:blue;"&gt;ORDER BY      &lt;/span&gt;ID &lt;span style="color:blue;"&gt;DESC&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Add the parameter mapping as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_0CA019A1.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_77AE972D.png" width="469" height="398" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the Result Set as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_53893C9E.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_3E97BA2B.png" width="482" height="410" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add three more parameters to the package as shown in the table below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_0580DD29.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_336E2FE1.png" width="627" height="103" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next configure the For Loop Properties as shown in the table below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_37787DB3.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_6565D06B.png" width="627" height="61" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The InitExpression value sets the @dtMDSLoopTimer to the current time plus the interval set in our @intMDSTimeout variable. The EvalExpression checks if the @strMDSBatchStatus is either not equal to 2 (Success) or the timeout has expired.&lt;/p&gt;

&lt;p&gt;The For Loop Container can only succeed if the staging batch is successfully loaded.&lt;/p&gt;

&lt;p&gt;Now we can validate the model so add an Execute SQL Task to the control flow and connect it to the ‘FLC – Wait Until Batch Completes’ task with a success constraint. Rename the task - mine is called ‘SQL – Validate Model’. Change the connection to MasterDataServices and the SQLStatement as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;@ModelName    &lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;50&lt;span style="color:gray;"&gt;) = &lt;/span&gt;?
&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;@UserName     &lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;50&lt;span style="color:gray;"&gt;) = &lt;/span&gt;?
&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;@User_ID      &lt;span style="color:blue;"&gt;INT 
DECLARE &lt;/span&gt;@Version_ID   &lt;span style="color:blue;"&gt;INT
DECLARE &lt;/span&gt;@Model_id     &lt;span style="color:blue;"&gt;INT 


SET &lt;/span&gt;@User_ID &lt;span style="color:gray;"&gt;=        (&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;ID  
                       &lt;span style="color:blue;"&gt;FROM  &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;tblUser u 
                       &lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;u&lt;span style="color:gray;"&gt;.&lt;/span&gt;UserName &lt;span style="color:gray;"&gt;= &lt;/span&gt;@UserName &lt;span style="color:gray;"&gt;) 

&lt;/span&gt;&lt;span style="color:blue;"&gt;SET &lt;/span&gt;@Version_ID &lt;span style="color:gray;"&gt;=     (&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:magenta;"&gt;MAX&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;ID&lt;span style="color:gray;"&gt;)  
                       &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;viw_SYSTEM_SCHEMA_VERSION  
                       &lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;Model_Name &lt;span style="color:gray;"&gt;= &lt;/span&gt;@ModelName&lt;span style="color:gray;"&gt;)
                   
&lt;/span&gt;&lt;span style="color:blue;"&gt;SET &lt;/span&gt;@Model_ID &lt;span style="color:gray;"&gt;=       (&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;Model_ID 
                       &lt;span style="color:blue;"&gt;FROM &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;viw_SYSTEM_SCHEMA_VERSION 
                       &lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;Model_Name &lt;span style="color:gray;"&gt;= &lt;/span&gt;@ModelName&lt;span style="color:gray;"&gt;) 


&lt;/span&gt;&lt;span style="color:blue;"&gt;EXECUTE &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;udpValidateModel @User_ID&lt;span style="color:gray;"&gt;, &lt;/span&gt;@Model_ID&lt;span style="color:gray;"&gt;, &lt;/span&gt;@Version_ID&lt;span style="color:gray;"&gt;, &lt;/span&gt;1&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Set the parameter mapping as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_13532324.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_7E61A0B0.png" width="540" height="457" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Almost done. Just to finish it off lets add a script task to the control flow and connect it to the ‘FLC – Wait Until Batch Completes’ task with a completion constraint. Change the Evaluation Operation of the constraint to ‘Expression and Constraint’ and set the Expression to ‘@strMDSBatchStatus != 2’. Edit the script and add the following line of code under&amp;#160;&amp;#160; // TODO: Add your code here:&lt;/p&gt;

&lt;pre class="code"&gt;Dts.Events.FireError(0, &lt;span style="color:#a31515;"&gt;&amp;quot;SCR - Fire Error&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;MDS Timeout Occurred&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty, 0);&lt;/pre&gt;

&lt;p&gt;This task will fire an error event if the MDS staging batch does not complete successfully.&lt;/p&gt;

&lt;p&gt;The finished package control flow should look similar to the following image:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_175D70F6.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_454AC3AE.png" width="524" height="575" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Execute this package and then check the Product entity in MDS. It should look something like the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_5E4693F3.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_6C18D9EE.png" width="644" height="482" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looking at the other entities you will see that we have added members to three entities and validated all these new members. &lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;Over the last two blog posts I have shown a way of automating the loading of data to Master Data Services via SSIS. This pattern can be used to cater for most of your loading requirements. &lt;/p&gt;

&lt;p&gt;That’s it, the completed Integration Services project source code and MDS Model can be downloaded from &lt;a href="http://blogs.adatis.co.uk/files"&gt;here&lt;/a&gt; – (You will need to create a login first).&lt;/p&gt;

&lt;p&gt;Your comments are very welcome.&lt;/p&gt;&lt;img src="http://blogs.adatis.co.uk/aggbug.aspx?PostID=9616" width="1" height="1"&gt;</description><category domain="http://blogs.adatis.co.uk/blogs/neil/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://blogs.adatis.co.uk/blogs/neil/archive/tags/Integration+Services/default.aspx">Integration Services</category><category domain="http://blogs.adatis.co.uk/blogs/neil/archive/tags/MDS/default.aspx">MDS</category><category domain="http://blogs.adatis.co.uk/blogs/neil/archive/tags/Master+Data+Services/default.aspx">Master Data Services</category><category domain="http://blogs.adatis.co.uk/blogs/neil/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>A Pattern To Load Data to Master Data Services via SSIS</title><link>http://blogs.adatis.co.uk/blogs/neil/archive/2011/07/14/a-pattern-to-load-data-to-master-data-services-via-ssis.aspx</link><pubDate>Thu, 14 Jul 2011 15:37:00 GMT</pubDate><guid isPermaLink="false">8d7d37f8-4a66-4c95-9fba-293fa87607dc:9298</guid><dc:creator>Neil Dobner</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.adatis.co.uk/blogs/neil/rsscomments.aspx?PostID=9298</wfw:commentRss><comments>http://blogs.adatis.co.uk/blogs/neil/archive/2011/07/14/a-pattern-to-load-data-to-master-data-services-via-ssis.aspx#comments</comments><description>&lt;h2&gt;&lt;/h2&gt;  &lt;h5&gt;Part 1&lt;/h5&gt;  &lt;h5&gt;Introduction&lt;/h5&gt;  &lt;p&gt;Loading new members to a MDS entity will be a common requirement in all MDS implementations. In these blog posts I am going to walk you through building an SSIS package that performs the following processes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Load new members and attributes to several entities via staging tables &lt;/li&gt;    &lt;li&gt;Validate the MDS model that contains the entities &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In part one we will load the MDS staging tables ready to take our new members and attributes into our MDS model. For a thorough understanding of the staging process in MDS please see the Master Data Services Team blog post on &lt;a href="http://sqlblog.com/blogs/mds_team/archive/2010/02/10/Importing-Data-by-Using-the-Staging-Process.aspx"&gt;Importing Data by Using the Staging Process&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;A pre-requisite is to have the AdventureWorks2008R2 database samples installed on the same instance of SQL Server as Master Data Services.&lt;/p&gt;  &lt;p&gt;In MDS I have created a model named ‘Product’ with an entity of the same name. The product entity has the following attributes which are set to the default type and length unless specified:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Name &lt;/li&gt;    &lt;li&gt;Code &lt;/li&gt;    &lt;li&gt;Model (Domain Attribute) &lt;/li&gt;    &lt;li&gt;Culture (Domain Attribute) &lt;/li&gt;    &lt;li&gt;Description (Text, 500) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;We are going to load this entity with Product data from the AdventureWorks2008R2 database using a SSIS package. &lt;/p&gt;  &lt;p&gt;In addition to this there are two further entities in the Product model:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Culture &lt;/li&gt;    &lt;li&gt;Model &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;These entities have just the code and name attributes and are set to the default type and length. &lt;/p&gt;  &lt;p&gt;The MDS model and Integration Services project source code can be downloaded from &lt;a href="http://blogs.adatis.co.uk/files"&gt;here&lt;/a&gt; – (You will need to create a login first).&lt;/p&gt;  &lt;h5&gt;Building The Solution&lt;/h5&gt;  &lt;p&gt;OK enough of the intro let’s get on and build the package.&lt;/p&gt;  &lt;p&gt;Start a new Visual Studio Integration Services Project and save the default package to a more suitable name. I’ve called mine ‘LoadMDS.dtsx’.&lt;/p&gt;  &lt;p&gt;Create the following connection managers as shown below remembering to replace the Server and MDS database names. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_09161AF0.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_2211EB35.png" width="347" height="354" /&gt;&lt;/a&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_68FB0E32.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_16E860EB.png" width="345" height="352" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Rename the connection managers to ‘AdventureWorks’ and ‘MasterDataServices’ respectively.&lt;/p&gt;  &lt;p&gt;Now we need to create some variables so go ahead and create the variables shown in the table below: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_5F871BC5.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_7882EC0A.png" width="601" height="128" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We are now ready to put our first task into our package. This task will optionally clear the staging tables of all successfully loaded members, attributes and relationships prior to loading, based on the value of the blnClearStage parameter.&lt;/p&gt;  &lt;p&gt;Add an Execute SQL Task to the control flow of your package and rename it - I’ve called mine ‘SQL – Clear Staging Tables’.&lt;/p&gt;  &lt;p&gt;On the General tab set the connection to MasterDataServices and the SQL Statement as follows:&lt;/p&gt;  &lt;div&gt;   &lt;blockquote&gt;     &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;@ModelName &lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;50&lt;span style="color:gray;"&gt;) = &lt;/span&gt;? 
&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;@UserName  &lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;50&lt;span style="color:gray;"&gt;) = &lt;/span&gt;? 
&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;@User_ID   &lt;span style="color:blue;"&gt;INT

SET &lt;/span&gt;@User_ID &lt;span style="color:gray;"&gt;=    (&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;ID  
                   &lt;span style="color:blue;"&gt;FROM  &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;tblUser u 
                   &lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;u&lt;span style="color:gray;"&gt;.&lt;/span&gt;UserName &lt;span style="color:gray;"&gt;= &lt;/span&gt;@UserName &lt;span style="color:gray;"&gt;) 

&lt;/span&gt;&lt;span style="color:blue;"&gt;IF &lt;/span&gt;? &lt;span style="color:gray;"&gt;= &lt;/span&gt;1 
    &lt;span style="color:blue;"&gt;EXECUTE &lt;/span&gt;mdm&lt;span style="color:gray;"&gt;.&lt;/span&gt;udpStagingClear @User_ID&lt;span style="color:gray;"&gt;, &lt;/span&gt;4&lt;span style="color:gray;"&gt;, &lt;/span&gt;1&lt;span style="color:gray;"&gt;, &lt;/span&gt;@ModelName&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:blue;"&gt;DEFAULT 
ELSE 
    SELECT &lt;/span&gt;1 &lt;span style="color:blue;"&gt;AS &lt;/span&gt;A&lt;/pre&gt;
  &lt;/blockquote&gt;
On the Parameter Mapping tab add the variables exactly as shown below:&lt;/div&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_2FE43130.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_76CD542D.png" width="455" height="387" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add a Data Flow task to the control flow of the package and connect it to the ‘SQL – Clear Staging Tables’ task with a success constraint. Rename the task to ‘DFL – Load Staging Tables’.&lt;/p&gt;

&lt;p&gt;Add three further variables to our package as follows: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_0041C13C.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_4B35320B.png" width="710" height="116" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the data flow of our package add an OLEDB data source task, set the connection to AdventureWorks and the Data Access Mode to SQL Command. Add the following SQL to the SQL command text window:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;SELECT 
    &lt;/span&gt;&lt;span style="color:magenta;"&gt;CAST&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;p&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductID &lt;span style="color:blue;"&gt;AS VARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;10&lt;span style="color:gray;"&gt;)) + &lt;/span&gt;pmx&lt;span style="color:gray;"&gt;.&lt;/span&gt;CultureID            &lt;span style="color:blue;"&gt;AS &lt;/span&gt;ProductCode
    &lt;span style="color:gray;"&gt;,&lt;/span&gt;p&lt;span style="color:gray;"&gt;.&lt;/span&gt;Name            
    &lt;span style="color:gray;"&gt;,&lt;/span&gt;p&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductModelID
    &lt;span style="color:gray;"&gt;,&lt;/span&gt;pm&lt;span style="color:gray;"&gt;.&lt;/span&gt;Name                                                    &lt;span style="color:blue;"&gt;AS &lt;/span&gt;ProductModelName
    &lt;span style="color:gray;"&gt;,&lt;/span&gt;pmx&lt;span style="color:gray;"&gt;.&lt;/span&gt;CultureID
    &lt;span style="color:gray;"&gt;,&lt;/span&gt;c&lt;span style="color:gray;"&gt;.&lt;/span&gt;Name                                                     &lt;span style="color:blue;"&gt;AS &lt;/span&gt;CultureName
    &lt;span style="color:gray;"&gt;,&lt;/span&gt;pd&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:blue;"&gt;Description
FROM &lt;/span&gt;Production&lt;span style="color:gray;"&gt;.&lt;/span&gt;Product                                         p 
  &lt;span style="color:gray;"&gt;INNER JOIN &lt;/span&gt;Production&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductModel                            pm 
    &lt;span style="color:blue;"&gt;ON &lt;/span&gt;p&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductModelID &lt;span style="color:gray;"&gt;= &lt;/span&gt;pm&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductModelID 
  &lt;span style="color:gray;"&gt;INNER JOIN &lt;/span&gt;Production&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductModelProductDescriptionCulture   pmx 
    &lt;span style="color:blue;"&gt;ON &lt;/span&gt;pm&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductModelID &lt;span style="color:gray;"&gt;= &lt;/span&gt;pmx&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductModelID
  &lt;span style="color:gray;"&gt;INNER JOIN &lt;/span&gt;Production&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductDescription                      pd 
    &lt;span style="color:blue;"&gt;ON &lt;/span&gt;pmx&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductDescriptionID &lt;span style="color:gray;"&gt;= &lt;/span&gt;pd&lt;span style="color:gray;"&gt;.&lt;/span&gt;ProductDescriptionID
  &lt;span style="color:gray;"&gt;INNER JOIN &lt;/span&gt;Production&lt;span style="color:gray;"&gt;.&lt;/span&gt;Culture                                 c
    &lt;span style="color:blue;"&gt;ON &lt;/span&gt;pmx&lt;span style="color:gray;"&gt;.&lt;/span&gt;CultureID &lt;span style="color:gray;"&gt;= &lt;/span&gt;c&lt;span style="color:gray;"&gt;.&lt;/span&gt;CultureID&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Don’t worry if the formatting turns ugly, that’s just what happens. Press the Preview button and you will see that this query will return us the following columns to our data flow:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ProductCode &lt;/li&gt;

  &lt;li&gt;Name &lt;/li&gt;

  &lt;li&gt;ProductModelID &lt;/li&gt;

  &lt;li&gt;ProductModelName &lt;/li&gt;

  &lt;li&gt;CultureID &lt;/li&gt;

  &lt;li&gt;CultureName &lt;/li&gt;

  &lt;li&gt;Description &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We need two more columns in our data flow and to get them we will use a Derived Column transformation task so drag one on to the data flow from the toolbox and connect it up to the data source. Add the columns as shown in the image below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_0FC92473.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_56B24770.png" width="528" height="436" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next the data flow needs to be duplicated into multiple streams so that the different members and attributes can be loaded to the staging tables. This is achieved by adding a Multicast transformation task to our data flow. This task does not require any configuration. There will be six outputs from the Multicast task and these will be used to load the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Product Members &lt;/li&gt;

  &lt;li&gt;Model Members &lt;/li&gt;

  &lt;li&gt;Culture Members &lt;/li&gt;

  &lt;li&gt;Product Model Attributes &lt;/li&gt;

  &lt;li&gt;Product Culture Attributes &lt;/li&gt;

  &lt;li&gt;Product Description Attributes &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each of these outputs needs to be tailored as to whether they will be loading a member or an attribute and also which member or attribute they are loading. Add six Derived Column transformation tasks to the data flow and connect them to the Multicast transformation. At this point our data flow should look similar to the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_41C0C4FD.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_1D9B6A6E.png" width="729" height="231" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For each of the Derived Column transformations add the additional columns as specified below: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_7163AF92.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_1F51024B.png" width="734" height="342" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OK now we have got all the information we need in our data flows to start loading to the staging tables but before we do that there is one more thing to do. As we are loading new members to the Model and Culture entities as well as Product we need to ensure that we have only distinct values for our member codes to prevent staging errors. To achieve this we add and connect Aggregate transformation shapes to the data flows underneath the ‘Add Culture Member Information’ and ‘Add Model Member Information’ shapes. The images below show how to configure these aggregate transformation shapes:&lt;/p&gt;

&lt;p&gt;Group By Culture&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Group By Model&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_08A9E7FB.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_4F930AF8.png" width="342" height="310" /&gt;&lt;/a&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_7D805DB0.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_167C2DF6.png" width="340" height="308" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are now ready to load the data to the MDS staging tables. Add six OLE DB destination shapes to the dataflow. Three of the destinations will be to load new entity members and the other three will be to load attributes for these new members. Configure the Connection Manager properties of the destinations as follows:&lt;/p&gt;

&lt;p&gt;Members&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Attributes&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_018AAB83.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_5D6550F3.png" width="327" height="284" /&gt;&lt;/a&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_4873CE80.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_0F5CF17E.png" width="328" height="283" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connect the first destination shape to the ‘Add Product Member Information’ shape and configure it as a member destination. Click the Mappings tab and set the Input and Destination column mappings as shown below: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_663A2548.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_5148A2D5.png" width="340" height="259" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connect the second destination shape to the ‘Group By Culture’ shape and configure it as a Member destination. The column mappings will be the same as above except for the MemberName and MemberCode columns and these will be set to CultureName and CultureID respectively.&lt;/p&gt;

&lt;p&gt;Connect the third destination shape to the ‘Group By Model’ shape and configure it as a Member destination. The column mappings will be the same as above except for the MemberName and MemberCode columns and these will be set to ProductModelName and ProductModelID respectively.&lt;/p&gt;

&lt;p&gt;Connect the fourth destination shape to the ‘Add Culture Attribute Information’ shape and configure it as an Attribute destination. The column mappings will be as follows: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_7F35F58D.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_1831C5D3.png" width="347" height="286" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Configure the next two destinations as Attribute destinations and map the columns as the other Attribute destination replacing the AttributeValue mapping with ProductModelID and Description respectively. Now our completed dataflow should look similar to the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.adatis.co.uk/blogs/neil/image_3D4A4436.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.adatis.co.uk/blogs/neil/image_thumb_5646147B.png" width="614" height="285" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you execute the package you will see that we have inserted 1764 Product member rows, 6 Culture member rows and 118 Model member rows into the mdm.tblStgMember table and 1764 attribute rows for each of the Culture, Model and Description attributes into the mdm.tblStgMemberAttribute table in your MDS database. It is worth noting that the data has now been staged only and we will not see it in our MDS entities yet.&lt;/p&gt;

&lt;p&gt;OK that’s as far as we are going to go in part one. In part two we will extend the package to move the data from the staging tables into the MDS model and validate the newly inserted data.&lt;/p&gt;&lt;img src="http://blogs.adatis.co.uk/aggbug.aspx?PostID=9298" width="1" height="1"&gt;</description><category domain="http://blogs.adatis.co.uk/blogs/neil/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://blogs.adatis.co.uk/blogs/neil/archive/tags/Integration+Services/default.aspx">Integration Services</category><category domain="http://blogs.adatis.co.uk/blogs/neil/archive/tags/MDS/default.aspx">MDS</category><category domain="http://blogs.adatis.co.uk/blogs/neil/archive/tags/Master+Data+Services/default.aspx">Master Data Services</category><category domain="http://blogs.adatis.co.uk/blogs/neil/archive/tags/SQL+Server/default.aspx">SQL Server</category></item></channel></rss>