<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tim laqua dot com &#187; How-to Guides</title>
	<atom:link href="http://timlaqua.com/category/how-to-guides/feed/" rel="self" type="application/rss+xml" />
	<link>http://timlaqua.com</link>
	<description>Thoughts and Code from Tim Laqua</description>
	<lastBuildDate>Fri, 16 Mar 2012 16:48:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Slowly Changing Dimensions with MD5 Hashes in SSIS</title>
		<link>http://timlaqua.com/2012/02/slowly-changing-dimensions-with-md5-hashes-in-ssis/</link>
		<comments>http://timlaqua.com/2012/02/slowly-changing-dimensions-with-md5-hashes-in-ssis/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 14:15:27 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[How-to Guides]]></category>
		<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[data warehousing]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=911</guid>
		<description><![CDATA[We recently moved away from the 3rd party Checksum component (and all 3rd party components) in SSIS and I wanted to share the pattern we settled on for maintaining our Type 1 Slowly Changing Dimensions (SCDs). There are two things we wanted to address with our new pattern. First, our previous implementation wasn't performing as [...]]]></description>
			<content:encoded><![CDATA[<p>We recently moved away from the 3rd party Checksum component (and all 3rd party components) in SSIS and I wanted to share the pattern we settled on for maintaining our Type 1 Slowly Changing Dimensions (SCDs).  There are two things we wanted to address with our new pattern.  First, our previous implementation wasn't performing as well as we needed it to or generating reliable checksums.  The second was that we wanted to get away from dependencies on custom assemblies in general.  To illustrate the pattern, we're going to build a SCD package off the Adventure Works DW DimCustomer table and skip over the actual source of the business keys and attributes by selecting directly from the completed dimension for now.</p>
<p>First, we assume that our dimension already exists (and we were using some other checksum or MERGE to maintain it).  We have to add a column to store the MD5 hash:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">DimCustomer</span> <span style="color: #0000FF;">ADD</span>
	MD5 <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">34</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">DEFAULT</span> <span style="color: #FF0000;">''</span></pre></div></div>

<p>Second, we need a staging table to store updated/changed rows.  Script out the current dimension as a CREATE, remove all unneeded constraints and indexes, and create a staging table as a heap:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>Staging_DimCustomer_UpdatedRows<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span>
	<span style="color: #808080;">&#91;</span>CustomerKey<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">INT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>GeographyKey<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">INT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>CustomerAlternateKey<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">15</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Title<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">8</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>FirstName<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>MiddleName<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>LastName<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>NameStyle<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>BirthDate<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATETIME</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>MaritalStatus<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Suffix<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">10</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Gender<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>EmailAddress<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>YearlyIncome<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">MONEY</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>TotalChildren<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">TINYINT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>NumberChildrenAtHome<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">TINYINT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>EnglishEducation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">40</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>SpanishEducation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">40</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>FrenchEducation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">40</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>EnglishOccupation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>SpanishOccupation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>FrenchOccupation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>HouseOwnerFlag<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>NumberCarsOwned<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">TINYINT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>AddressLine1<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">120</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>AddressLine2<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">120</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Phone<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">20</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>DateFirstPurchase<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATETIME</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>CommuteDistance<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">15</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>MD5<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">34</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>Now in to SSIS - We will be building:</p>
<ol>
<li>Execute SQL Task to Truncate our Staging table(s)</li>
<li>Data Flow Task to Insert new rows and Stage updated rows</li>
<ol>
<li>OLE DB Source to retrieve our source data</li>
<li>Script Component to Generate Row Numbers</li>
<li>Conditional Split to Evenly Distribute Rows</li>
<li>Script Component to Generate MD5 Hashes</li>
<li>Union All to Squish it all back together</li>
<li>Lookup to get the existing MD5 Hash (if it exists)</li>
<li>Conditional Split to separate Unchanged and Changed rows</li>
<li>RowCount Transformation </li>
<li>OLE DB Destination for Changed rows</li>
<li>OLE DB Destination for New rows</li>
</ol>
<li>Execute SQL Task to Update changed rows</li>
</ol>
<p><em>Completed Control Flow</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/CompletedControlFlow.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/CompletedControlFlow.png" alt="" title="CompletedControlFlow" width="268" height="229" class="alignnone size-full wp-image-925" /></a></p>
<p><em>Completed Data Flow</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/CompletedDataFlow.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/CompletedDataFlow.png" alt="" title="CompletedDataFlow" width="619" height="636" class="alignnone size-full wp-image-926" /></a></p>
<p><span id="more-911"></span></p>
<h5>1: Execute SQL Task to Truncate our Staging table(s)</h5>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">TRUNCATE</span> <span style="color: #0000FF;">TABLE</span> Staging_DimCustomer_UpdatedRows;</pre></div></div>

<h5>2.1: OLE DB Source to retrieve our source data</h5>
<p><em>Configure the Connection Manager - for the source we'll just select from the dimension minus the surrogate key and MD5 column:</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-1-Query1.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-1-Query1.png" alt="" title="2-1 Query" width="832" height="721" class="alignnone size-full wp-image-954" /></a></p>
<p><em>You most likely won't need to exclude any columns - here we unselect the surrogate key and the MD5 column:</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-1-Columns.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-1-Columns.png" alt="" title="2-1 Columns" width="831" height="719" class="alignnone size-full wp-image-934" /></a></p>
<h5>2.2: Script Component to Generate Row Numbers</h5>
<p><em>Add one output column to Output 0 in your Row Number Script Transformation</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-2-Output-Column.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-2-Output-Column.png" alt="" title="2-2 Output Column" width="838" height="724" class="alignnone size-full wp-image-936" /></a></p>
<p><em>The following code will assign the current row number and increment it for the next row through the buffer:</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Data</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.SqlServer.Dts.Pipeline.Wrapper</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.SqlServer.Dts.Runtime.Wrapper</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>Microsoft.<span style="color: #0000FF;">SqlServer</span>.<span style="color: #0000FF;">Dts</span>.<span style="color: #0000FF;">Pipeline</span>.<span style="color: #0000FF;">SSISScriptComponentEntryPointAttribute</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ScriptMain <span style="color: #008000;">:</span> UserComponent
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">int</span> _rowCount <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Input0_ProcessInputRow<span style="color: #000000;">&#40;</span>Input0Buffer Row<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        Row.<span style="color: #0000FF;">RowNumber</span> <span style="color: #008000;">=</span> _rowCount<span style="color: #008000;">++;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h5>2.3: Conditional Split to Evenly Distribute Rows</h5>
<p><em>Now in the conditional split, we distribute rows across multiple outputs by using the modulo operator.  Modify to suit the number of threads you need to remove any bottlenecks in the MD5 calculation (you may only need one thread):</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-3-Conditional-Split-Outputs.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-3-Conditional-Split-Outputs.png" alt="" title="2-3 Conditional Split Outputs" width="742" height="721" class="alignnone size-full wp-image-937" /></a></p>
<h5>2.4: Script Component to Generate MD5 Hashes</h5>
<p><em>Add one output column to Output 0 in your Generate MD5 Script Transformation</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-4-Output-Columns.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-4-Output-Columns.png" alt="" title="2-4 Output Columns" width="832" height="721" class="alignnone size-full wp-image-938" /></a></p>
<p>Select all input columns or just select ones that are going to be in the hash.  Since we explicitly specify columns in the script, the hash will only be generated with exactly what columns you tell it to use.</p>
<p><em>The following script will generate a string representation of a MD5 hash.  We do this so that we can do direct comparisons with HASHBYTES converted output (and virtually everything likes dealing with strings better than binary).  We do end up doubling the storage cost of the MD5 hash by storing it as a string, but we were fine with that:</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Data</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.SqlServer.Dts.Pipeline.Wrapper</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.SqlServer.Dts.Runtime.Wrapper</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>Microsoft.<span style="color: #0000FF;">SqlServer</span>.<span style="color: #0000FF;">Dts</span>.<span style="color: #0000FF;">Pipeline</span>.<span style="color: #0000FF;">SSISScriptComponentEntryPointAttribute</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ScriptMain <span style="color: #008000;">:</span> UserComponent
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Security</span>.<span style="color: #0000FF;">Cryptography</span></span>.<span style="color: #0000FF;">MD5</span> _md5 <span style="color: #008000;">=</span>
                <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Security</span>.<span style="color: #0000FF;">Cryptography</span></span>.<span style="color: #0000FF;">MD5CryptoServiceProvider</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Input0_ProcessInputRow<span style="color: #000000;">&#40;</span>Input0Buffer Row<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">try</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span> hashSource <span style="color: #008000;">=</span>
                <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">GeographyKey_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">GeographyKey</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">Title_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">Title</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">FirstName_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">FirstName</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">MiddleName_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">MiddleName</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">LastName_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">LastName</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">NameStyle_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">NameStyle</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">BirthDate_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">BirthDate</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">MaritalStatus_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">MaritalStatus</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">Suffix_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">Suffix</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">Gender_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">Gender</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">EmailAddress_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">EmailAddress</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">YearlyIncome_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">YearlyIncome</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">TotalChildren_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">TotalChildren</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">NumberChildrenAtHome_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">NumberChildrenAtHome</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">EnglishEducation_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">EnglishEducation</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">SpanishEducation_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">SpanishEducation</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">FrenchEducation_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">FrenchEducation</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">EnglishOccupation_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">EnglishOccupation</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">SpanishOccupation_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">SpanishOccupation</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">FrenchOccupation_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">FrenchOccupation</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">HouseOwnerFlag_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">HouseOwnerFlag</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">NumberCarsOwned_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">NumberCarsOwned</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">AddressLine1_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">AddressLine1</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">AddressLine2_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">AddressLine2</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">Phone_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">Phone</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">DateFirstPurchase_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">DateFirstPurchase</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>Row.<span style="color: #0000FF;">CommuteDistance_IsNull</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> Row.<span style="color: #0000FF;">CommuteDistance</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> hashBytes <span style="color: #008000;">=</span> _md5.<span style="color: #0000FF;">ComputeHash</span><span style="color: #000000;">&#40;</span>
                <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">UnicodeEncoding</span>.<span style="color: #0000FF;">Unicode</span>.<span style="color: #0000FF;">GetBytes</span><span style="color: #000000;">&#40;</span>hashSource<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">StringBuilder</span> sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">StringBuilder</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> hashBytes.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                sb.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>hashBytes<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;X2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            Row.<span style="color: #0000FF;">MD5</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;0x&quot;</span> <span style="color: #008000;">+</span> sb.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Row.<span style="color: #0000FF;">MD5</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Error&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>To quickly generate the string concatenation statement:</p>
<ol>
<li>Script DimCustomer As SELECT to Clipboard and paste in to Notepad++</li>
<li>Search > Replace... (Ctrl+H)</li>
<li>Select Regular expression for Search Mode</li>
<li><strong>Find:</strong> ^.*?\[(.*?)\].*$</li>
<li><strong>Replace:</strong> + (Row.\1_IsNull ? "" : Row.\1)</li>
<li>Replace All, remove the leading +, and remove the garbage at the bottom, remove surrogate and business keys</li>
<li>Paste results in to the script</li>
<li>Add .ToString() to non-string columns and fix any column names (issues will be underlined in red)</li>
</ol>
<p>Copy your completed script component once for each thread you'll be running.  When you copy a script component, you need to actually open the script after copying it and click Edit Script before it will validate.</p>
<h5>2.5: Union All to Squish it all back together</h5>
<h5>2.6: Lookup to get the existing MD5 Hash (if it exists)</h5>
<p><em>Configure the Lookup component to redirect rows with no matches to the No Match output:</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-6-Redirect-Rows-to-No-Match.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-6-Redirect-Rows-to-No-Match.png" alt="" title="2-6 Redirect Rows to No Match" width="832" height="721" class="alignnone size-full wp-image-941" /></a></p>
<p><em>For your connection, select the surrogate key, business key(s), and MD5 hash from your existing dimension table:</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-6-Connection-Settings.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-6-Connection-Settings.png" alt="" title="2-6 Connection Settings" width="832" height="721" class="alignnone size-full wp-image-940" /></a></p>
<p><em>Lookup based on the business key(s) and bring back the existing MD5 and surrogate key</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-6-Column-Settings.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-6-Column-Settings.png" alt="" title="2-6 Column Settings" width="832" height="721" class="alignnone size-full wp-image-939" /></a></p>
<h5>2.7: Conditional Split to separate Unchanged and Changed rows</h5>
<p><em>Name the output for rows where the ExistingMD5 is the same as the new MD5 "Ignore" and name the Default output "Update"</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-7-Conditional-Outputs.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-7-Conditional-Outputs.png" alt="" title="2-7 Conditional Outputs" width="742" height="721" class="alignnone size-full wp-image-942" /></a></p>
<h5>2.8: RowCount Transformation for Ignored Rows</h5>
<p><em>For your Ignored Rows Row Count transformation, you'll have to create a variable to store the rowcount in (we don't use it, but that's just how the transformation works):</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-8-Ignored-Rows-Settings.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-8-Ignored-Rows-Settings.png" alt="" title="2-8 Ignored Rows Settings" width="799" height="721" class="alignnone size-full wp-image-943" /></a></p>
<h5>2.9: OLE DB Destination for Changed rows</h5>
<p><em>We'll insert rows that need to be updated in to the previously created Staging_DimCustomer_UpdatedRows table:</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-9-Connection-Manager.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-9-Connection-Manager.png" alt="" title="2-9 Connection Manager" width="832" height="721" class="alignnone size-full wp-image-944" /></a></p>
<h5>2.10: OLE DB Destination for New rows</h5>
<p><em>Finally, insert new rows directly in to the dimension:</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/2-10-Connection-Manager.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/2-10-Connection-Manager.png" alt="" title="2-10 Connection Manager" width="832" height="721" class="alignnone size-full wp-image-945" /></a></p>
<h5>3: Execute SQL Task to Update changed rows</h5>
<p><em>The final step is to take those rows we staged for updating and actually perform the update:</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">UPDATE</span> a <span style="color: #0000FF;">SET</span>
 <span style="color: #808080;">&#91;</span>GeographyKey<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>GeographyKey<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>CustomerAlternateKey<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>CustomerAlternateKey<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>Title<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>Title<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>FirstName<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>FirstName<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>MiddleName<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>MiddleName<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>LastName<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>LastName<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>NameStyle<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>NameStyle<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>BirthDate<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>BirthDate<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>MaritalStatus<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>MaritalStatus<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>Suffix<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>Suffix<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>Gender<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>Gender<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>EmailAddress<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>EmailAddress<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>YearlyIncome<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>YearlyIncome<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>TotalChildren<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>TotalChildren<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>NumberChildrenAtHome<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>NumberChildrenAtHome<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>EnglishEducation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>EnglishEducation<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>SpanishEducation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>SpanishEducation<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>FrenchEducation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>FrenchEducation<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>EnglishOccupation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>EnglishOccupation<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>SpanishOccupation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>SpanishOccupation<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>FrenchOccupation<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>FrenchOccupation<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>HouseOwnerFlag<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>HouseOwnerFlag<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>NumberCarsOwned<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>NumberCarsOwned<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>AddressLine1<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>AddressLine1<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>AddressLine2<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>AddressLine2<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>Phone<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>Phone<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>DateFirstPurchase<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>DateFirstPurchase<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>CommuteDistance<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>CommuteDistance<span style="color: #808080;">&#93;</span>
,<span style="color: #808080;">&#91;</span>MD5<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>MD5<span style="color: #808080;">&#93;</span> 
<span style="color: #0000FF;">FROM</span> DimCustomer a
	 <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> Staging_DimCustomer_UpdatedRows b
		<span style="color: #0000FF;">ON</span> a.<span style="color: #202020;">CustomerKey</span> <span style="color: #808080;">=</span> b.<span style="color: #202020;">CustomerKey</span></pre></div></div>

<p>To quickly generate the update statement:</p>
<ol>
<li>Script DimCustomer As SELECT to Clipboard and paste in to Notepad++</li>
<li>Search > Replace... (Ctrl+H)</li>
<li>Select Regular expression for Search Mode</li>
<li><strong>Find:</strong> ^.*?\[(.*?)\].*$</li>
<li><strong>Replace:</strong> ,[\1] = b.[\1]</li>
<li>Replace All, remove surrogate key and garbage at the bottom, remove leading comma</li>
<li>Add UPDATE a SET at the top</li>
<li>Add appropriate FROM clause at the bottom</li>
</ol>
<p>And bob's your uncle.</p>
<h5>In closing...</h5>
<p><strong>Why not write a reusable code block for the MD5 hash that you could cut and paste?  Why hardcode columns?</strong><br />
Well, there's really only two ways to do it dynamically.  One is to loop over each column in the InputBuffer and concatenate them.  Man, that's a bunch of extra logic when we know very well what columns are, null handling is a little sketch, and proper datatype handling requires some special logic.  Looping over the InputBuffer also just plain feels dirty.  The second option is Reflection.  Now we could approach reflection two ways - first we could iterate over the Row definition and concatenate the columns for each InputRow, but this is INCREDIBLY expensive (reflection is crazy slow).  The second Reflection approach would be to construct a DynamicMethod at runtime and call that dynamic method for each row.  While this could certainly be as fast as hardcoding, it's very obscure and difficult for most people to understand.  Do you want code in your packages that's hard to understand?</p>
<p>We chose hardcode the columns because this is the absolute minimum amount of work that needs to be done to generate a reliable MD5 hash and is therefore the fastest possible solution.</p>
<p><strong>Why not do that Reflection and DynamicMethod thing in a custom transformation?</strong><br />
Because one of the main goals here was to rid ourselves of 3rd party dependencies (all custom assembly dependencies really) and we wanted to do the minimum amount of work required to generated a reliable MD5 hash.</p>
<p><strong>Why bulk update at the end rather than update each row via OLE DB Command?</strong><br />
Because the OLE DB Command isn't set based and it can block/be blocked by inserts.  Also, parameter mapping to all those Param_XX parameters and counting question marks is just terrible.  So, so terrible.</p>
<p><strong>How do I know how many threads I need to distribute the MD5 calculation over?</strong><br />
First we'll usually watch the source query in the database engine to see what it's waiting on.  PREEMPTIVE_OS_WAITFORSINGLEOBJECT tends to point at SQL Server waiting to send data to SSIS because it's not accepting rows fast enough.  For a starting point, take your source query and see how long it takes to just insert the entire thing in to a heap - somewhere around there is what we're shooting for.  Faster if you ignore many rows, slower if you update/insert many rows.</p>
<p><strong>How does it perform?</strong><br />
It's ridiculously fast.  One of our dimensions (55 columns, varying datatypes, ~5 million deep, ~4.5 million evaluated for changes 3 times a day) went from 50+ minutes per run to 5-9 minutes per run.  More importantly, we were previously using the CRC32 algorithm in the Checksum transform and that wasn't producing reliable checksums so we would either update unchanged rows or even miss changes to rows - now the hashes are dead on and reproducible via HASHBYTES.</p>
<p>As a side note, we were able to get Checksum to keep up with sql server by spreading it across 6 threads but the lack of reliable output forced us to abandon it.</p>
<p><strong>Is there a quick way to mimic the SSIS MD5 using HASHBYTES?</strong></p>
<ol>
<li>Script DimCustomer As SELECT to Clipboard and paste in to Notepad++</li>
<li>Search > Replace... (Ctrl+H)</li>
<li>Select Regular expression for Search Mode</li>
<li><strong>Find:</strong> ^.*?\[(.*?)\].*$</li>
<li><strong>Replace:</strong> +ISNULL(CAST([\1] AS NVARCHAR(255)),N'')</li>
<li>Replace All, remove surrogate key, business key(s), leading +, and garbage at the bottom</li>
<li>Add <strong>CONVERT(VARCHAR(34), HASHBYTES('md5',</strong> at the top</li>
<li>Add <strong>),1) AS [Hashbytes]</strong> and an appropriate FROM clause at the bottom</li>
</ol>
<p>Now if all your columns are chars, nchars, varchars, nvarchars, ints, and decimals - you're good.  If some of your columns are the more unique datatypes (datetime, money, bit, etc) - then you've got more work to do.  The issue lies in the difference between how sql server converts these datatypes to NVARCHAR and how C# converts them to strings.  Here are a few examples:</p>
<table cellpadding=0 cellspacing="0">
<tr>
<th>Datatype</th>
<th>SQL Conversion</th>
<th>C# Conversion</th>
</tr>
<tr>
<td>DATETIME</td>
<td>1966-04-08 00:00:00.000</td>
<td>4/8/1966 12:00:00 AM</td>
</tr>
<tr>
<td>MONEY</td>
<td>70000.00</td>
<td>70000</td>
</tr>
<tr>
<td>BIT</td>
<td>1</td>
<td>True</td>
</tr>
<tr>
<td>BIT</td>
<td>0</td>
<td>False</td>
</tr>
</table>
<p>The dates are the biggest debacle as they're sensitive to localization settings.  If you actually had to generate the hashes using HASHBYTES on a regular basis, we would recommend modifying the date formatting when concatenating columns for the hashSource variable in the script so they match sql server.  For us, we only generate MD5s using HASHBYTES for troubleshooting and updating the hash using purely dim columns rather than relying on the source as some business keys no longer exist in the source.</p>
<p><em>Here's the finished tsql for the above hash:</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> 
 CustomerKey
,CustomerAlternateKey
,MD5
,<span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">34</span><span style="color: #808080;">&#41;</span>, HASHBYTES<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'md5'</span>,
IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>GeographyKey<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>Title<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>FirstName<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>MiddleName<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>LastName<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>NameStyle<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> N<span style="color: #FF0000;">'True'</span> <span style="color: #0000FF;">ELSE</span> N<span style="color: #FF0000;">'False'</span> <span style="color: #0000FF;">END</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span>
<span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">MONTH</span>,<span style="color: #808080;">&#91;</span>BirthDate<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span><span style="color: #FF0000;">'/'</span><span style="color: #808080;">+</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">DAY</span>,<span style="color: #808080;">&#91;</span>BirthDate<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span><span style="color: #FF0000;">'/'</span><span style="color: #808080;">+</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">YEAR</span>,<span style="color: #808080;">&#91;</span>BirthDate<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">4</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span><span style="color: #FF0000;">' '</span><span style="color: #808080;">+</span><span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">RIGHT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">NVARCHAR</span>, <span style="color: #808080;">&#91;</span>BirthDate<span style="color: #808080;">&#93;</span>, <span style="color: #000;">109</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">14</span><span style="color: #808080;">&#41;</span>,<span style="color: #000;">8</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span><span style="color: #FF0000;">' '</span><span style="color: #808080;">+</span><span style="color: #0000FF;">RIGHT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">NVARCHAR</span>, <span style="color: #808080;">&#91;</span>BirthDate<span style="color: #808080;">&#93;</span>, <span style="color: #000;">109</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span>
,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>MaritalStatus<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>Suffix<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>Gender<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>EmailAddress<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>YearlyIncome <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">FLOAT</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>TotalChildren<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>NumberChildrenAtHome<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>EnglishEducation<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>SpanishEducation<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>FrenchEducation<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>EnglishOccupation<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>SpanishOccupation<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>FrenchOccupation<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>HouseOwnerFlag<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>NumberCarsOwned<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>AddressLine1<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>AddressLine2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>Phone<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span>
<span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">MONTH</span>,DateFirstPurchase<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span><span style="color: #FF0000;">'/'</span><span style="color: #808080;">+</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">DAY</span>,DateFirstPurchase<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span><span style="color: #FF0000;">'/'</span><span style="color: #808080;">+</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">YEAR</span>,DateFirstPurchase<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">4</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span><span style="color: #FF0000;">' '</span><span style="color: #808080;">+</span><span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">RIGHT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">NVARCHAR</span>, DateFirstPurchase, <span style="color: #000;">109</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">14</span><span style="color: #808080;">&#41;</span>,<span style="color: #000;">8</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span><span style="color: #FF0000;">' '</span><span style="color: #808080;">+</span><span style="color: #0000FF;">RIGHT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">NVARCHAR</span>, DateFirstPurchase, <span style="color: #000;">109</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span>
,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">+</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>CommuteDistance<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,N<span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>,<span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Hashbytes<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> DimCustomer</pre></div></div>

<p><em>And the results:</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2012/02/HASHBYTES-Results.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/HASHBYTES-Results.png" alt="" title="HASHBYTES Results" width="720" height="169" class="alignnone size-full wp-image-960" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2012/02/slowly-changing-dimensions-with-md5-hashes-in-ssis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Troubleshooting: 1998 Jeep Grand Cherokee (ZJ) Doesn&#8217;t Start &#8211; Cranks, No Fuel, No Spark</title>
		<link>http://timlaqua.com/2011/07/troubleshooting-1998-jeep-grand-cherokee-zj-doesnt-start-cranks-no-fuel-no-spark/</link>
		<comments>http://timlaqua.com/2011/07/troubleshooting-1998-jeep-grand-cherokee-zj-doesnt-start-cranks-no-fuel-no-spark/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 02:45:02 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[How-to Guides]]></category>
		<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=714</guid>
		<description><![CDATA[This has been one of the most frustrating repairs we have come across. One day the Jeep just plain refused to start anymore. We have had prolonged starting times for a while now where we will let fuel pump prime at least twice before it would start, but it would always start. Nothing really precluded [...]]]></description>
			<content:encoded><![CDATA[<p>This has been one of the most frustrating repairs we have come across.  One day the Jeep just plain refused to start anymore.  We have had prolonged starting times for a while now where we will let fuel pump prime at least twice before it would start, but it would always start.  Nothing really precluded the no start condition, we just turned it off one day and it didn't want to start again.  The symptoms don't really point to any particular component (other than the PCM) and without some fancy tools, you'll do exactly what we did - replace the PCM... and it won't fix anything.  So we took out our fancy tool, looked up some diagnostic diagrams on <a href="http://www.alldatadiy.com/" title="alldatadiy.com">alldatadiy.com</a>, and got to work.</p>
<p>A few things to check for right away to see if you're having the same issue we were:</p>
<ul>
<li>Check to see if the fuel pump runs during cranking - ours didn't</li>
<li>Check for spark during cranking - we didn't have any</li>
<li>Check to see if your check engine light is on (ours WASN'T)</li>
<li>Check your voltage and fuel gauges with the ignition on - ours didn't register anything</li>
<li>Check to see if your low fuel light is on - our was</li>
<p><a href="http://timlaqua.com/wp-content/uploads/2011/07/FuelLightSymptom.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/FuelLightSymptom-1024x764.jpg" alt="" title="FuelLightSymptom" width="550" height="410" class="alignnone size-large wp-image-728" /></a><br />
<span id="more-714"></span></p>
<p>Fancy tool time - we hooked up the Genisys EVO to the data link connecter (located under the steering wheel):<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/DataLinkLocation.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/DataLinkLocation-1024x764.jpg" alt="" title="DataLinkLocation" width="550" height="410" class="alignnone size-large wp-image-718" /></a></p>
<p>We first tried to connect to the PCM computer to view the Datastream (and check codes) - whatever it would tell us:<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/EVOComputerSelection.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/EVOComputerSelection-764x1024.jpg" alt="" title="EVOComputerSelection" width="550" height="737" class="alignnone size-large wp-image-723" /></a></p>
<p>Aaaaand it said it didn't want to talk to us:<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/EVOPCMFail.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/EVOPCMFail-764x1024.jpg" alt="" title="EVOPCMFail" width="550" height="737" class="alignnone size-large wp-image-725" /></a></p>
<p>Then we moved on to the BUS monitor to see if the bus was up and what computers we could talk to:<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/EVOBUSMonitor.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/EVOBUSMonitor-764x1024.jpg" alt="" title="EVOBUSMonitor" width="550" height="737" class="alignnone size-large wp-image-722" /></a></p>
<p>Looks like the Body computer (BCM) is willing to talk to us:<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/EVOBCMOk.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/EVOBCMOk-764x1024.jpg" alt="" title="EVOBCMOk" width="550" height="737" class="alignnone size-large wp-image-721" /></a></p>
<p>Now, we see the bus is up, the PCM appears to be down - so we replaced the PCM.  Unfortunately replacing the PCM did absolutely nothing for us other than lighten our wallets.  At this point, we did some digging on AllDataDiy for an appropriate troubleshooting test to figure out what on earth was going on.  While I can't re-publish their content due to the ToS agreement, I can tell you how we arrived at our final solution.</p>
<p>We started by testing the Throttle Position Sensor voltages:<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/ThrottlePositionSensor.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/ThrottlePositionSensor-1024x764.jpg" alt="" title="ThrottlePositionSensor" width="550" height="410" class="alignnone size-large wp-image-731" /></a></p>
<p>Pin 3 should be above 4 volts:<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/DMMLow.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/DMMLow-1024x764.jpg" alt="" title="DMMLow" width="550" height="410" class="alignnone size-large wp-image-720" /></a></p>
<p>Since it was under 4 volts, we unplugged the Camshaft Position Sensor (connector locations below - this is the passenger side of the engine compartment):<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/PositionSensorsArrows.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/PositionSensorsArrows-1024x764.jpg" alt="" title="PositionSensorsArrows" width="550" height="410" class="alignnone size-large wp-image-739" /></a></p>
<p>And checked again - still under 4 volts:<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/DMMLow.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/DMMLow-1024x764.jpg" alt="" title="DMMLow" width="550" height="410" class="alignnone size-large wp-image-720" /></a></p>
<p>Then we unplugged the Crankshaft Position Sensor and checked voltage again:<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/DMMHish.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/DMMHish-1024x764.jpg" alt="" title="DMMHish" width="550" height="410" class="alignnone size-large wp-image-719" /></a></p>
<p>Finally, a bad component!  We replaced the Crankshaft Position Sensor and verified that all was well<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/CrankshaftPositionSensor.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/CrankshaftPositionSensor-1024x764.jpg" alt="" title="CrankshaftPositionSensor" width="550" height="410" class="alignnone size-large wp-image-717" /></a></p>
<p>Fuel Gauges now work, voltage works, and the low fuel light isn't on anymore<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/FuelGaugeWorking.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/FuelGaugeWorking-1024x764.jpg" alt="" title="FuelGaugeWorking" width="550" height="410" class="alignnone size-large wp-image-727" /></a></p>
<p>We started it up and checked the ECM datastream again - all systems go<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/EVOGoodDatastream.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/EVOGoodDatastream-764x1024.jpg" alt="" title="EVOGoodDatastream" width="550" height="737" class="alignnone size-large wp-image-724" /></a></p>
<p>Now, the troubleshooting procedure we started out with had us unplug the ECM at the beginning and then test the TPS pin 3 voltage - but these pictures are from us reproducing it after the fact and we forgot to unplug the ECM first... so we logged a code:<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/07/EVOTPSCode.jpg"><img src="http://timlaqua.com/wp-content/uploads/2011/07/EVOTPSCode-764x1024.jpg" alt="" title="EVOTPSCode" width="550" height="737" class="alignnone size-large wp-image-726" /></a></p>
<p>I mention this code just as a side note - we cleared the code with the EVO, but if you just ignore it long enough it'll go away after a few cycles.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/07/troubleshooting-1998-jeep-grand-cherokee-zj-doesnt-start-cranks-no-fuel-no-spark/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>BlackBerry Storm (9530) Error: SIM Card Rejected</title>
		<link>http://timlaqua.com/2008/11/blackberry-storm-9530-error-sim-card-rejected/</link>
		<comments>http://timlaqua.com/2008/11/blackberry-storm-9530-error-sim-card-rejected/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 16:12:45 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[How-to Guides]]></category>
		<category><![CDATA[blackberry]]></category>
		<category><![CDATA[blackberry 9530]]></category>
		<category><![CDATA[blackberry storm]]></category>
		<category><![CDATA[cdma]]></category>
		<category><![CDATA[gsm]]></category>
		<category><![CDATA[network technology]]></category>
		<category><![CDATA[sim card]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=54</guid>
		<description><![CDATA[This error pops up when you lose CDMA (1XEV) connectivity in the US and the phone attempts to connect to a GSM network (you can duplicate if you force your Storm to GSM network technology) and you have a Global SIM card installed (and most of us do). The kicker is that the message "SIM [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right"><a href='http://timlaqua.com/wp-content/uploads/2008/11/sim-card-rejected-message.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/11/sim-card-rejected-message.jpg" alt="" title="sim-card-rejected-message" width="360" height="480" class="alignright size-full wp-image-55" /></a></div>
<p>This error pops up when you lose CDMA (1XEV) connectivity in the US and the phone attempts to connect to a GSM network (you can duplicate if you force your Storm to GSM network technology) and you have a Global SIM card installed (and most of us do).  The kicker is that the message "SIM Card Rejected" doesn't go away until your hard reboot - even after you've reconnected to the CDMA network.</p>
<p>So, if you're not using your Global SIM (if you are, call VZW and ask for Global Support - they can activate your SIM), you can just force CDMA only on the phone, do a battery pull, and you'll never see this again.  I assume some future firmware update will handle this error better by making it go away once you're back on CDMA, but for now - this is what I had to do:</p>
<div style="clear: both"></div>
<p><span id="more-54"></span></p>
<ol>
<li>Select Options from the menu:<br />
<a href='http://timlaqua.com/wp-content/uploads/2008/11/options-selection.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/11/options-selection.jpg" alt="" title="options-selection" width="360" height="480" class="alignnone size-full wp-image-59" /></a>
</li>
<li>Select Mobile Network Options:<br />
<a href='http://timlaqua.com/wp-content/uploads/2008/11/options-screen.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/11/options-screen.jpg" alt="" title="options-screen" width="360" height="480" class="alignnone size-full wp-image-58" /></a>
</li>
<li>Change the Network Technology from Global to 1XEV:<br />
<a href='http://timlaqua.com/wp-content/uploads/2008/11/mobile-network-options.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/11/mobile-network-options.jpg" alt="" title="mobile-network-options" width="360" height="480" class="alignnone size-full wp-image-56" /></a><a href='http://timlaqua.com/wp-content/uploads/2008/11/network-technology-selection.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/11/network-technology-selection.jpg" alt="" title="network-technology-selection" width="360" height="480" class="alignnone size-full wp-image-57" /></a></p>
</li>
<li>Pull the battery out, put it back in, and once it reboots - the error will be gone and won't reappear.
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2008/11/blackberry-storm-9530-error-sim-card-rejected/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Installing ASTrace.exe in a 64-bit environment</title>
		<link>http://timlaqua.com/2008/11/installing-astraceexe-in-a-64-bit-environment/</link>
		<comments>http://timlaqua.com/2008/11/installing-astraceexe-in-a-64-bit-environment/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 03:12:55 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[How-to Guides]]></category>
		<category><![CDATA[Scripts & Code]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=51</guid>
		<description><![CDATA[ASTrace.exe is part of the SQL Server Analysis Services Community Samples on CodePlex. This utility works just fine in a 32-bit environment, however some of the assemblies needed to interact with Analysis Services do not have 64-bit counterparts - thus, you have to use WOW64 to get the service to work properly on a x64 [...]]]></description>
			<content:encoded><![CDATA[<p>ASTrace.exe is part of the SQL Server Analysis Services Community Samples on CodePlex.  This utility works just fine in a 32-bit environment, however some of the assemblies needed to interact with Analysis Services do not have 64-bit counterparts - thus, you have to use WOW64 to get the service to work properly on a x64 machine.</p>
<p><strong>ASTrace</strong> can be downloaded here:<br /><a href="http://www.codeplex.com/SQLSrvAnalysisSrvcs/Release/ProjectReleases.aspx?ReleaseId=13572">http://www.codeplex.com/SQLSrvAnalysisSrvcs/Release/ProjectReleases.aspx?ReleaseId=13572</a></p>
<p>32-bit Installation Instructions can be found here:<br /><a href="http://msdn.microsoft.com/en-us/library/bb283156(SQL.90).aspx"></p>
<p>http://msdn.microsoft.com/en-us/library/bb283156(SQL.90).aspx</a></p>
<p>And to get it to work on x64, you need to do two things differently:</p>
<ul>
<li>Target x86 processors when you build the application - this way, your 64-bit OS will use WOW64 when the service runs (<strong>Project</strong> > <strong>ASTrace Properties...</strong> > <strong>Build Tab</strong>).<br />
<a href='http://timlaqua.com/wp-content/uploads/2008/11/astrace1.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/11/astrace1-300x201.jpg" alt="" title="astrace1" width="300" height="201" class="alignnone size-medium wp-image-52" /></a></p>
<li>Create the following registry key and string value pointing to where you copied the ASTrace files:<br />
<code>[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ASTrace]<br />
"path"="C:\\ASTrace"</code>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2008/11/installing-astraceexe-in-a-64-bit-environment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to add a calculated measure (calculated field) to an Excel 2007 PivotTable with a SSAS data source</title>
		<link>http://timlaqua.com/2008/11/how-to-add-a-calculated-measure-calculated-field-to-an-excel-2007-pivottable-with-a-ssas-data-source/</link>
		<comments>http://timlaqua.com/2008/11/how-to-add-a-calculated-measure-calculated-field-to-an-excel-2007-pivottable-with-a-ssas-data-source/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 18:28:12 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[How-to Guides]]></category>
		<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[calculated measure]]></category>
		<category><![CDATA[calculated member]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[excel 2007]]></category>
		<category><![CDATA[named set]]></category>
		<category><![CDATA[pivottable]]></category>
		<category><![CDATA[ssas]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=50</guid>
		<description><![CDATA[As it turns out, you can do it programatically as explained by Allan Folting here: Microsoft Excel: Common Questions Around Excel 2007 OLAP PivotTables: http://blogs.msdn.com/excel/archive/2008/02/05/common-questions-around-excel-2007-OLAP-PivotTables.aspx And the parts that I have to keep looking up (I use my blog as a notebook for things I don't want to forget : Sub AddCalculatedMeasure() Dim pvt As [...]]]></description>
			<content:encoded><![CDATA[<p>As it turns out, you can do it programatically as explained by <strong>Allan Folting </strong>here:<br />
<strong>Microsoft Excel: Common Questions Around Excel 2007 OLAP PivotTables</strong>:<br />
<a href="http://blogs.msdn.com/excel/archive/2008/02/05/common-questions-around-excel-2007-OLAP-PivotTables.aspx">http://blogs.msdn.com/excel/archive/2008/02/05/common-questions-around-excel-2007-OLAP-PivotTables.aspx</a></p>
<p>And the parts that I have to keep looking up (I use my blog as a notebook for things I don't want to forget <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> :</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Sub</span> AddCalculatedMeasure() 
	<span style="color: #000080;">Dim</span> pvt <span style="color: #000080;">As</span> PivotTable
	<span style="color: #000080;">Dim</span> strName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
	<span style="color: #000080;">Dim</span> strFormula <span style="color: #000080;">As</span> <span style="color: #000080;">String</span> 
&nbsp;
	<span style="color: #000080;">Set</span> pvt = Sheet1.PivotTables(&quot;PivotTable1&quot;)
	strName = &quot;[Measures].[Internet Sales Amount 25 %]&quot;
	strFormula = &quot;[Measures].[Internet Sales Amount]*1.25&quot;
	pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, <span style="color: #000080;">Type</span>:=xlCalculatedMember 
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span> 
&nbsp;
<span style="color: #000080;">Sub</span> AddCalculatedMember() 
	<span style="color: #000080;">Dim</span> pvt <span style="color: #000080;">As</span> PivotTable
	<span style="color: #000080;">Dim</span> strName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
	<span style="color: #000080;">Dim</span> strFormula <span style="color: #000080;">As</span> <span style="color: #000080;">String</span> 
&nbsp;
	<span style="color: #000080;">Set</span> pvt = Sheet1.PivotTables(&quot;PivotTable1&quot;)
	strName = &quot;[Product].[Product Categories].[Bikes].[Mountain Bikes].[Mountain-100 Silver, 38 25 %]&quot;
	strFormula = &quot;[Product].[Product Categories].[Bikes].[Mountain Bikes].[Mountain-100 Silver, 38]*1.25&quot;
	pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, <span style="color: #000080;">Type</span>:=xlCalculatedMember
	pvt.ViewCalculatedMembers = <span style="color: #000080;">True</span> 
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span> 
&nbsp;
<span style="color: #000080;">Sub</span> AddNamedSet() 
	<span style="color: #000080;">Dim</span> pvt <span style="color: #000080;">As</span> PivotTable
	<span style="color: #000080;">Dim</span> strName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
	<span style="color: #000080;">Dim</span> strFormula <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
	<span style="color: #000080;">Dim</span> cbf <span style="color: #000080;">As</span> CubeField 
&nbsp;
	<span style="color: #000080;">Set</span> pvt = Sheet1.PivotTables(&quot;PivotTable1&quot;)
	strName = &quot;[My Mountain Bikes]&quot;
	strFormula = &quot;[Product].[Product Categories].[Bikes].[Mountain Bikes].children&quot;
	pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, <span style="color: #000080;">Type</span>:=xlCalculatedSet
	<span style="color: #000080;">Set</span> cbf = pvt.CubeFields.AddSet(Name:=&quot;[My Mountain Bikes]&quot;, Caption:=&quot;Mountain Bikes&quot;) 
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p>He also mentions that you can expose these members to Excel Services 2007 by creating the new objects and then removing the VBA code - very useful article.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2008/11/how-to-add-a-calculated-measure-calculated-field-to-an-excel-2007-pivottable-with-a-ssas-data-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to replace the battery in a Polar F11 Heart Rate Monitor (HRM)</title>
		<link>http://timlaqua.com/2008/09/how-to-replace-the-battery-in-a-polar-f11-heart-rate-monitor-hrm/</link>
		<comments>http://timlaqua.com/2008/09/how-to-replace-the-battery-in-a-polar-f11-heart-rate-monitor-hrm/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 23:40:58 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[How-to Guides]]></category>
		<category><![CDATA[f11]]></category>
		<category><![CDATA[heart rate monitor]]></category>
		<category><![CDATA[hrm]]></category>
		<category><![CDATA[polar]]></category>
		<category><![CDATA[polar f11]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=47</guid>
		<description><![CDATA[Disclaimer: The user manual for the Polar F11 clearly states to take the HRM to a Polar dealer and have them replace the battery - taking the back off could void your warranty. If you wish to be 100% sure that you maintain the water-resistant seal and do not want to void your warranty - [...]]]></description>
			<content:encoded><![CDATA[<p>Disclaimer: The user manual for the Polar F11 clearly states to take the HRM to a Polar dealer and have them replace the battery - taking the back off could void your warranty.  If you wish to be 100% sure that you maintain the water-resistant seal and do not want to void your warranty - or risk breaking your HRM (certainly a possibility when you take it apart...), take the unit to an authorized Polar dealer and have them replace the battery.</p>
<table>
<tr>
<td>
Step 1: Remove the back cover (4 little screws - make sure you have the right size screwdriver or you'll strip them out).  Also note that the back has a water-resistant seal - keep this clean and remember that there is always a chance that the seal may be damaged if you do this yourself.
</td>
<td></td>
</tr>
<tr>
<td>
Step 2: Remove the internal unit from the watch casing (it just pulls out).
</td>
<td><a href='http://timlaqua.com/wp-content/uploads/2008/09/polarf11-internal.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/09/polarf11-internal-150x150.jpg" alt="" title="polarf11-internal" width="150" height="150" class="alignnone size-thumbnail wp-image-44" /></a></td>
</tr>
<tr>
<td>
Step 3: Get something to pry the battery latch tab with (I used another small screwdriver)
</td>
<td><a href='http://timlaqua.com/wp-content/uploads/2008/09/polarf11-batterylocktab.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/09/polarf11-batterylocktab-150x150.jpg" alt="" title="polarf11-batterylocktab" width="150" height="150" class="alignnone size-thumbnail wp-image-42" /></a></td>
</tr>
<tr>
<td>
Step 4: Take whatever you used to pry the latch tab out with and use it to pry the battery up by placing the device (screwdriver in my case) in the notch above the latch (see picture).
</td>
<td><a href='http://timlaqua.com/wp-content/uploads/2008/09/polarf11-batteryprynotch.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/09/polarf11-batteryprynotch-150x150.jpg" alt="" title="polarf11-batteryprynotch" width="150" height="150" class="alignnone size-thumbnail wp-image-43" /></a></td>
</tr>
<tr>
<td>
Step 5: Go to Wal-Mart and purchase a new CR2032 watch battery (you may want to do this before hand... I didn't know what battery it used so I had to take it out first) - runs about $3.50.
</td>
<td><a href='http://timlaqua.com/wp-content/uploads/2008/09/polarf11-internalnexttobattery.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/09/polarf11-internalnexttobattery-150x150.jpg" alt="" title="polarf11-internalnexttobattery" width="150" height="150" class="alignnone size-thumbnail wp-image-46" /></a></td>
</tr>
<tr>
<td>
Step 6: Put the battery back in and put everything back together.
</td>
<td><a href='http://timlaqua.com/wp-content/uploads/2008/09/polarf11-afterbatteryreplacement.jpg'><img src="http://timlaqua.com/wp-content/uploads/2008/09/polarf11-afterbatteryreplacement-150x150.jpg" alt="" title="polarf11-afterbatteryreplacement" width="150" height="150" class="alignnone size-thumbnail wp-image-41" /></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2008/09/how-to-replace-the-battery-in-a-polar-f11-heart-rate-monitor-hrm/feed/</wfw:commentRss>
		<slash:comments>223</slash:comments>
		</item>
	</channel>
</rss>

