<?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</title>
	<atom:link href="http://timlaqua.com/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>Automating PowerPivot Data Refresh in Sharepoint 2010</title>
		<link>http://timlaqua.com/2012/03/automating-powerpivot-data-refresh-in-sharepoint-2010/</link>
		<comments>http://timlaqua.com/2012/03/automating-powerpivot-data-refresh-in-sharepoint-2010/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 00:56:57 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[sharepoint]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=977</guid>
		<description><![CDATA[Of course we want to do this, it's a fundamental requirement. Dear Sharepoint, please refresh my PowerPivot when the data is ready, not on some arbitrary schedule. Until this functionality is built-in, people will continue to hack away at it to figure out how to make this happen. Is this supported? Certainly not - so [...]]]></description>
			<content:encoded><![CDATA[<p>Of course we want to do this, it's a fundamental requirement.  Dear Sharepoint, please refresh my PowerPivot when the data is ready, not on some arbitrary schedule.  Until this functionality is built-in, people will continue to hack away at it to figure out how to make this happen.  Is this supported?  Certainly not - so continue at your own risk.</p>
<p>So the method we'll be using here is just to mimic what Sharepoint does when you check the box to "Also refresh as soon as possible" in the schedule configuration page.  To accomplish this we open the profiler, connect it to whatever instance our Sharepoint PowerPivot database is hosted on and filter you TextData to "%Schedule%" or filter to just the Sharepoint PowerPivot database (SP2010_PowerPivot_Service_Application in our case) - then open up your test PowerPivot schedule configuration, check the box, click OK, wait for the schedule history to come back up and then stop the trace.  Now you know you've got what you need, you just have to find it:</p>
<p><a href="http://timlaqua.com/wp-content/uploads/2012/03/Profiler-Events.jpg"><img src="http://timlaqua.com/wp-content/uploads/2012/03/Profiler-Events.jpg" alt="" title="Profiler Events" width="797" height="56" class="alignnone size-full wp-image-978" /></a><br />
<span id="more-977"></span><br />
So here we have Sharepoint asking for information about the schedule (identified by the ItemID from DataRefresh.Items) and then passing the data it received to PersistSchedule.  If you take a close look at the PersistSchedule parameters, the last one is @RunNow = 1.  So clearly, this is what we're after.  We went the most tedious route and manually looked up the ItemID in DataRefresh.Items:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @ItemID <span style="color: #0000FF;">UNIQUEIDENTIFIER</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'30D39B0E-DA8B-489B-A713-3B29D208B51F'</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span>
	@ItemName <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;">200</span><span style="color: #808080;">&#41;</span>,
	@SPSiteID <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">UNIQUEIDENTIFIER</span><span style="color: #808080;">&#93;</span>,
	@SPWebID <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">UNIQUEIDENTIFIER</span><span style="color: #808080;">&#93;</span>,	
	@LastModifiedBy <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;">450</span><span style="color: #808080;">&#41;</span>,
	@ScheduleLastUpdatedBy <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;">450</span><span style="color: #808080;">&#41;</span>,
	@UserIdentity <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;">450</span><span style="color: #808080;">&#41;</span>,
	@EmailNotification <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>, 
	@EmailList <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;">450</span><span style="color: #808080;">&#41;</span>,
	@SecurityConfiguration <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">INT</span><span style="color: #808080;">&#93;</span>,
	@SSApplicationID <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;">256</span><span style="color: #808080;">&#41;</span>,
	@ProcessAllDataSources <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>,
	@RV <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIGINT</span><span style="color: #808080;">&#93;</span>,
	<span style="color: #008080;">-- Schedule info</span>
	@Enabled <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>, 
	<span style="color: #008080;">-- Schedule details</span>
	@NextProcessDate <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATETIME</span><span style="color: #808080;">&#93;</span>,
	@ScheduleStartDate <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATETIME</span><span style="color: #808080;">&#93;</span>,
	@FrequencyKey <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>,
	@RepeatFrequency <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">INT</span><span style="color: #808080;">&#93;</span>,
	@Sunday <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>,
	@Monday <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>,
	@Tuesday <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>,
	@Wednesday <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>,
	@Thursday <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>,
	@Friday <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>,
	@Saturday <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>,
	@Weekday <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>, 
	@WeekendDay <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>, 
	@<span style="color: #0000FF;">DAY</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>, 
	@MonthlyPeriod <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">TINYINT</span><span style="color: #808080;">&#93;</span>, 
	@MonthlySpecificDay <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">INT</span><span style="color: #808080;">&#93;</span>, 
	@ProcessAfterBusinessHours <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>, 
	@SpecificTime <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATETIME</span><span style="color: #808080;">&#93;</span>,
	@RunNow <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIT</span><span style="color: #808080;">&#93;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Schedule <span style="color: #0000FF;">TABLE</span> <span style="color: #808080;">&#40;</span>
	<span style="color: #808080;">&#91;</span>ItemID<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">UNIQUEIDENTIFIER</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>Enabled<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>RV<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">BIGINT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>ItemName<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;">200</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>SPSiteID<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">UNIQUEIDENTIFIER</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>SPWebID<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">UNIQUEIDENTIFIER</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>UserIdentity<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;">450</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>LastModifiedBy<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;">450</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>EmailNotification<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>EmailList<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;">450</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>SecurityConfiguration<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>SSApplicationID<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;">256</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>ProcessAllDataSources<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>ScheduleDetailID<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">UNIQUEIDENTIFIER</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>ScheduleStartDate<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>FrequencyKey<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>RepeatFrequency<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>Sunday<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Monday<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Tuesday<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Wednesday<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Thursday<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Friday<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Saturday<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>WeekDay<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>WeekendDay<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DAY</span><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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>MonthlyPeriod<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>MonthlySpecificDay<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>ProcessAfterBusinessHours<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;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>SpecificTime<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;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @Schedule
<span style="color: #0000FF;">EXEC</span> DataRefresh.<span style="color: #202020;">GetSchedule</span> @ItemID
&nbsp;
<span style="color: #0000FF;">SELECT</span> 
	 @ItemName <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>ItemName<span style="color: #808080;">&#93;</span>
	,@SPSiteID <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>SPSiteID<span style="color: #808080;">&#93;</span>
	,@SPWebID <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>SPWebID<span style="color: #808080;">&#93;</span>
	,@LastModifiedBy <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>LastModifiedBy<span style="color: #808080;">&#93;</span>
	,@ScheduleLastUpdatedBy <span style="color: #808080;">=</span> N<span style="color: #FF0000;">'DOMAIN<span style="color: #000099; font-weight: bold;">\t</span>laqua'</span>
	,@UserIdentity <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>UserIdentity<span style="color: #808080;">&#93;</span>
	,@EmailNotification <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>EmailNotification<span style="color: #808080;">&#93;</span>
	,@EmailList <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>EmailList<span style="color: #808080;">&#93;</span>
	,@SecurityConfiguration <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>SecurityConfiguration<span style="color: #808080;">&#93;</span>
	,@SSApplicationID <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>SSApplicationID<span style="color: #808080;">&#93;</span>
	,@ProcessAllDataSources <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>ProcessAllDataSources<span style="color: #808080;">&#93;</span>
	,@RV <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>RV<span style="color: #808080;">&#93;</span>
		<span style="color: #008080;">-- Schedule info</span>
	,@Enabled <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Enabled<span style="color: #808080;">&#93;</span>
		<span style="color: #008080;">-- Schedule details</span>
	,@NextProcessDate <span style="color: #808080;">=</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">DATE</span><span style="color: #808080;">&#41;</span>
	,@ScheduleStartDate <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>ScheduleStartDate<span style="color: #808080;">&#93;</span>
	,@FrequencyKey <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>FrequencyKey<span style="color: #808080;">&#93;</span>
	,@RepeatFrequency <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>RepeatFrequency<span style="color: #808080;">&#93;</span>
	,@Sunday <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Sunday<span style="color: #808080;">&#93;</span>
	,@Monday <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Monday<span style="color: #808080;">&#93;</span>
	,@Tuesday <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Tuesday<span style="color: #808080;">&#93;</span>
	,@Wednesday <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Wednesday<span style="color: #808080;">&#93;</span>
	,@Thursday <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Thursday<span style="color: #808080;">&#93;</span>
	,@Friday <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Friday<span style="color: #808080;">&#93;</span>
	,@Saturday <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Saturday<span style="color: #808080;">&#93;</span>
	,@Weekday <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Weekday<span style="color: #808080;">&#93;</span>
	,@WeekendDay <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>WeekendDay<span style="color: #808080;">&#93;</span>
	,@<span style="color: #0000FF;">DAY</span> <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DAY</span><span style="color: #808080;">&#93;</span>
	,@MonthlyPeriod <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>MonthlyPeriod<span style="color: #808080;">&#93;</span>
	,@MonthlySpecificDay <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>MonthlySpecificDay<span style="color: #808080;">&#93;</span>
	,@ProcessAfterBusinessHours <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>ProcessAfterBusinessHours<span style="color: #808080;">&#93;</span>
	,@SpecificTime <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>SpecificTime<span style="color: #808080;">&#93;</span>
	,@RunNow <span style="color: #808080;">=</span> <span style="color: #000;">1</span>
<span style="color: #0000FF;">FROM</span> @Schedule
&nbsp;
<span style="color: #0000FF;">EXEC</span> DataRefresh.<span style="color: #202020;">PersistSchedule</span>
	 @ItemID <span style="color: #808080;">=</span> @ItemID
	,@ItemName <span style="color: #808080;">=</span> @ItemName
	,@SPSiteID <span style="color: #808080;">=</span> @SPSiteID
	,@SPWebID <span style="color: #808080;">=</span> @SPWebID
	,@LastModifiedBy <span style="color: #808080;">=</span> @LastModifiedBy
	,@ScheduleLastUpdatedBy <span style="color: #808080;">=</span> @ScheduleLastUpdatedBy
	,@UserIdentity <span style="color: #808080;">=</span> @UserIdentity
	,@EmailNotification <span style="color: #808080;">=</span> @EmailNotification
	,@EmailList <span style="color: #808080;">=</span> @EmailList
	,@SecurityConfiguration <span style="color: #808080;">=</span> @SecurityConfiguration
	,@SSApplicationID <span style="color: #808080;">=</span> @SSApplicationID
	,@ProcessAllDataSources <span style="color: #808080;">=</span> @ProcessAllDataSources
	,@RV <span style="color: #808080;">=</span> @RV
		<span style="color: #008080;">-- Schedule info</span>
	,@Enabled <span style="color: #808080;">=</span> @Enabled
		<span style="color: #008080;">-- Schedule details</span>
	,@NextProcessDate <span style="color: #808080;">=</span> @NextProcessDate
	,@ScheduleStartDate <span style="color: #808080;">=</span> @ScheduleStartDate
	,@FrequencyKey <span style="color: #808080;">=</span> @FrequencyKey
	,@RepeatFrequency <span style="color: #808080;">=</span> @RepeatFrequency
	,@Sunday <span style="color: #808080;">=</span> @Sunday
	,@Monday <span style="color: #808080;">=</span> @Monday
	,@Tuesday <span style="color: #808080;">=</span> @Tuesday
	,@Wednesday <span style="color: #808080;">=</span> @Wednesday
	,@Thursday <span style="color: #808080;">=</span> @Thursday
	,@Friday <span style="color: #808080;">=</span> @Friday
	,@Saturday <span style="color: #808080;">=</span> @Saturday
	,@Weekday <span style="color: #808080;">=</span> @Weekday
	,@WeekendDay <span style="color: #808080;">=</span> @WeekendDay
	,@<span style="color: #0000FF;">DAY</span> <span style="color: #808080;">=</span> @<span style="color: #0000FF;">DAY</span>
	,@MonthlyPeriod <span style="color: #808080;">=</span> @MonthlyPeriod
	,@MonthlySpecificDay <span style="color: #808080;">=</span> @MonthlySpecificDay
	,@ProcessAfterBusinessHours <span style="color: #808080;">=</span> @ProcessAfterBusinessHours
	,@SpecificTime <span style="color: #808080;">=</span> @SpecificTime
	,@RunNow <span style="color: #808080;">=</span> @RunNow</pre></div></div>

<p>The only parameters that don't come from GetSchedule are NextRunDate which we set to midnight of today and RunNow which is, of course, 1 and ScheduleLastModifiedBy (I just tossed my username in there, I assume you could use the system identity as well).</p>
<p>And then we set it up to refresh every 10 minutes via Agent job to test:</p>
<p><a href="http://timlaqua.com/wp-content/uploads/2012/03/Schedule-History.jpg"><img src="http://timlaqua.com/wp-content/uploads/2012/03/Schedule-History.jpg" alt="" title="Schedule History" width="535" height="365" class="alignnone size-full wp-image-979" /></a></p>
<p>Happy refreshing!  Let me know if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2012/03/automating-powerpivot-data-refresh-in-sharepoint-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>SSAS Cache Isn&#8217;t Making Cents</title>
		<link>http://timlaqua.com/2012/02/ssas-cache-isnt-making-cents/</link>
		<comments>http://timlaqua.com/2012/02/ssas-cache-isnt-making-cents/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 23:12:27 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[ssas]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=888</guid>
		<description><![CDATA[I stole the pun from my Business Analyst, Mr. John Seiler Now on to my issue - when SSAS caches the value for my [Actual] measure, it seems to do so based on the results of the first query that requests that coordinate. In this particular cube, there's bunches of tiny fractions and depending on [...]]]></description>
			<content:encoded><![CDATA[<p>I stole the pun from my Business Analyst, Mr. John Seiler <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   Now on to my issue - when SSAS caches the value for my [Actual] measure, it seems to do so based on the results of the first query that requests that coordinate.  In this particular cube, there's bunches of tiny fractions and depending on how you slice it, it aggregates a little different.  This is a fun problem in itself, but the part that drives me (and the Finance department) crazy is that if you go and slice on something OTHER than that first query that created the cache, the values they see don't always add up to the "Grand Total" in Excel - aka. "All"</p>
<p>These are the queries used for this test:</p>
<p>Query A</p>

<div class="wp_syntax"><div class="code"><pre class="mdx" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">SELECT</span> 
	<span style="color: #003300; font-weight: bold;">&#123;</span>Actual<span style="color: #003300; font-weight: bold;">&#125;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">0</span>
<span style="color: #0000FF; font-weight: bold;">FROM</span> <span style="color: #333333;">[GL]</span> 
CELL <span style="color: #FF00FF;">PROPERTIES</span> <span style="color: #CC00FF;">VALUE</span></pre></div></div>

<p>Query B</p>

<div class="wp_syntax"><div class="code"><pre class="mdx" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">SELECT</span> 
	<span style="color: #003300; font-weight: bold;">&#123;</span>Actual<span style="color: #003300; font-weight: bold;">&#125;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span>
	<span style="color: #0000FF; font-weight: bold;">NON</span> <span style="color: #0000FF; font-weight: bold;">EMPTY</span> <span style="color: #0000FF;">Hierarchize</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #003300; font-weight: bold;">&#123;</span><span style="color: #0000FF;">DrilldownLevel</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #003300; font-weight: bold;">&#123;</span><span style="color: #333333;">[Account]</span>.<span style="color: #333333;">[Accounts]</span>.<span style="color: #333333;">[All]</span><span style="color: #003300; font-weight: bold;">&#125;</span><span style="color: #66cc66;">,,,</span>INCLUDE_CALC_MEMBERS<span style="color: #003300; font-weight: bold;">&#41;</span><span style="color: #003300; font-weight: bold;">&#125;</span><span style="color: #003300; font-weight: bold;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">1</span>
<span style="color: #0000FF; font-weight: bold;">FROM</span> <span style="color: #333333;">[GL]</span> 
CELL <span style="color: #FF00FF;">PROPERTIES</span> <span style="color: #CC00FF;">VALUE</span></pre></div></div>

<p>Query C</p>

<div class="wp_syntax"><div class="code"><pre class="mdx" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">SELECT</span> 
	<span style="color: #003300; font-weight: bold;">&#123;</span>Actual<span style="color: #003300; font-weight: bold;">&#125;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span>
	<span style="color: #0000FF; font-weight: bold;">NON</span> <span style="color: #0000FF; font-weight: bold;">EMPTY</span> <span style="color: #0000FF;">Hierarchize</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #003300; font-weight: bold;">&#123;</span><span style="color: #0000FF;">DrilldownLevel</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #003300; font-weight: bold;">&#123;</span><span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #333333;">[All]</span><span style="color: #003300; font-weight: bold;">&#125;</span><span style="color: #66cc66;">,,,</span>INCLUDE_CALC_MEMBERS<span style="color: #003300; font-weight: bold;">&#41;</span><span style="color: #003300; font-weight: bold;">&#125;</span><span style="color: #003300; font-weight: bold;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">1</span>
<span style="color: #0000FF; font-weight: bold;">FROM</span> <span style="color: #333333;">[GL]</span> 
CELL <span style="color: #FF00FF;">PROPERTIES</span> <span style="color: #CC00FF;">VALUE</span>
GO</pre></div></div>

<style>
td {vertical-align: top;}
</style>
<p>Results (Cache was cleared with ClearCache on the entire Database before each Series)</p>
<table cellpadding=0 cellspacing=0>
<tr>
<th>Series 1</th>
<th>Series 2</th>
<th>Series 3</th>
</tr>
<tr>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-A.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-A.png" alt="" title="Series 1 - Query A" width="134" height="41" class="alignnone size-full wp-image-890" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-B.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-B.png" alt="" title="Series 2 - Query B" width="182" height="126" class="alignnone size-full wp-image-894" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-C.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-C.png" alt="" title="Series 3 - Query C" width="177" height="115" class="alignnone size-full wp-image-898" /></a>
  </td>
</tr>
<tr>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-B.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-B.png" alt="" title="Series 1 - Query B" width="181" height="124" class="alignnone size-full wp-image-891" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-C.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-C.png" alt="" title="Series 2 - Query C" width="179" height="117" class="alignnone size-full wp-image-895" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-A.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-A.png" alt="" title="Series 3 - Query A" width="132" height="38" class="alignnone size-full wp-image-896" /></a>
  </td>
<tr>
<tr>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-C.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-C.png" alt="" title="Series 1 - Query C" width="176" height="116" class="alignnone size-full wp-image-892" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-A.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-A.png" alt="" title="Series 2 - Query A" width="136" height="39" class="alignnone size-full wp-image-893" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-B.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-B.png" alt="" title="Series 3 - Query B" width="182" height="143" class="alignnone size-full wp-image-897" /></a>
  </td>
<tr>
</table>
<p>So basically the Grand Total of this GL cube is a random number based on whoever sneaks the first query in after the cache is cleared (processing, sync, etc).</p>
<p>And for all of you that think the MDX script breaks everything everywhere - I did comment out my entire MDX script before running these tests.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2012/02/ssas-cache-isnt-making-cents/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Uncivil UNIONs</title>
		<link>http://timlaqua.com/2012/02/uncivil-unions/</link>
		<comments>http://timlaqua.com/2012/02/uncivil-unions/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 16:12:43 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=878</guid>
		<description><![CDATA[If you asked any SQL Server Developer or DBA what UNION does, they would tell you it combines two result sets. Then if you were to ask them if they knew it removed duplicates without the ALL argument, they would say yes. That's academic, but I dare you to go look at their and your [...]]]></description>
			<content:encoded><![CDATA[<p>If you asked any SQL Server Developer or DBA what UNION does, they would tell you it combines two result sets.  Then if you were to ask them if they knew it removed duplicates without the ALL argument, they would say yes.  That's academic, but I dare you to go look at their and your code and see how often UNION without the ALL argument is used.  UNION is evil.  Why do I say that?  Because DISTINCT is evil and blocking operations are evil so it follows that UNION is evil.</p>
<p>Would you be OK with the following query as the source for a fact table?</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">DISTINCT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span>
<span style="color: #808080;">&#40;</span>
  <span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">DISTINCT</span> <span style="color: #808080;">&#91;</span>c1<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>c2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>t1<span style="color: #808080;">&#93;</span>
  <span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
  <span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">DISTINCT</span> <span style="color: #808080;">&#91;</span>c1<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>c2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>t2<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#41;</span> a</pre></div></div>

<p>No?  Then why are you OK with this?</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span>c1<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>c2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>t1<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span>c1<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>c2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>t2<span style="color: #808080;">&#93;</span></pre></div></div>

<p>Personally, I tend to use UNION to combine data from two different sources.  For example, if I wanted to combine the sales transactions from two JDE instances - the query might look like:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span>c1<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>c2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>JDE1<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>F42119<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span>c1<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>c2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>JDE2<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>F42119<span style="color: #808080;">&#93;</span></pre></div></div>

<p>Each line here in a sales detail represents a line on an order, so assuming you selected all the PK columns in your query, a UNION won't remove any rows within either set, but when combined - it's possible the same PK could exist in both systems.  Now you could split hairs and say it's highly unlikely the rest of the row would be identical, but that's not the point - it's wrong to ever DISTINCT a set of transactions intended for creating a fact table.  Sure, in this particular case you could add a "SourceSystem" column that would stop that, but then you still have to accept that the UNION is blocking and expensive.  Just because a DISTINCT doesn't modify results doesn't mean it didn't do any work - it actually did a great deal of work.  Now consider that we're usually not selecting 2 columns, we're selecting 10-20. Do you want to wait for it to figure out all the rows are distinct when you already knew that?  Further, if they're not distinct you probably screwed up a JOIN somewhere.</p>
<p>As far as coding standards regarding UNION go, I would suggest never using UNION without the ALL clause and doing your DISTINCT elsewhere if that's actually what you intended.  Does that seem silly?  Yes - but I would wager you won't ever use the 2nd one outside of building Dimensions.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span>c1<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>c2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>JDE1<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>F42119<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span>c1<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>c2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>JDE2<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>F42119<span style="color: #808080;">&#93;</span>
&nbsp;
<span style="color: #008080;">--OR</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">DISTINCT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span>
<span style="color: #808080;">&#40;</span>
  <span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span>c1<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>c2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>JDE1<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>F42119<span style="color: #808080;">&#93;</span>
  <span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
  <span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span>c1<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>c2<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>JDE2<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>F42119<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#41;</span></pre></div></div>

<p>And don't get me started on unioning subqueries with GROUP BY's - Why don't you just throw half your processers in the garbage, light tempdb on fire and put all your data in heaps.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2012/02/uncivil-unions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hiding SSRS Schedule Jobs In SSMS</title>
		<link>http://timlaqua.com/2012/01/hiding-ssrs-schedule-jobs-in-ssms/</link>
		<comments>http://timlaqua.com/2012/01/hiding-ssrs-schedule-jobs-in-ssms/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 14:26:16 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[ssrs]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=864</guid>
		<description><![CDATA[Everybody hates these things. If you're in the Activity Monitor or browsing via the SSMS tree view, these GUID jobs that represent SSRS subscriptions are really just none of our concern. Sure, I can admit that I've seen people manually fire these to re-send a given subscription, but you can just do that using the [...]]]></description>
			<content:encoded><![CDATA[<p>Everybody hates these things.  If you're in the Activity Monitor or browsing via the SSMS tree view, these GUID jobs that represent SSRS subscriptions are really just none of our concern.  Sure, I can admit that I've seen people manually fire these to re-send a given subscription, but you can just do that using the AddEvent proc in a query window.  Personally - I don't want to see these... usually...</p>
<p>Connect to the database instance you want to filter the agent jobs out on<br />
Browse to Databases > System Databases > msdb > Programmability > Stored Procedures > System Stored Procedures<br />
Right-click on dbo.sp_help_category and select Modify...</p>
<p>At the top, change the definition of @where_clause to NVARCHAR(MAX)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>19
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;">  <span style="color: #0000FF;">DECLARE</span> @where_clause   <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span></pre></td></tr></table></div>

<p>At the bottom, add in a few lines to append the @where_clause variable with a predicate that filters out the Report Server category when it's you from your workstation (so you can still see that category from another machine if you need to).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;">  <span style="color: #0000FF;">SELECT</span> @cmd <span style="color: #808080;">=</span> @cmd <span style="color: #808080;">+</span> N<span style="color: #FF0000;">'FROM msdb.dbo.syscategories '</span>
&nbsp;
  <span style="color: #0000FF;">SET</span> @where_clause <span style="color: #808080;">+=</span> N<span style="color: #FF0000;">'
  AND
	CASE
		WHEN 
			name = '</span><span style="color: #FF0000;">'Report Server'</span><span style="color: #FF0000;">' 
			AND (
				SELECT RTRIM(nt_username) + '</span><span style="color: #FF0000;">'|'</span><span style="color: #FF0000;">' + RTRIM(hostname) 
				FROM sys.sysprocesses 
				where spid = @@spid) = '</span><span style="color: #FF0000;">'tlaqua|TIMSLAPTOP'</span><span style="color: #FF0000;">'  THEN 0
		ELSE 1
	END = 1 '</span>
&nbsp;
  <span style="color: #008080;">-- Execute the query</span>
  <span style="color: #0000FF;">EXECUTE</span> <span style="color: #808080;">&#40;</span>@cmd <span style="color: #808080;">+</span> @where_clause <span style="color: #808080;">+</span> N<span style="color: #FF0000;">'ORDER BY category_type, name'</span><span style="color: #808080;">&#41;</span>
&nbsp;
  <span style="color: #0000FF;">RETURN</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">@@ERROR</span><span style="color: #808080;">&#41;</span> <span style="color: #008080;">-- 0 means success</span>
<span style="color: #0000FF;">END</span></pre></td></tr></table></div>

<p>So, what on earth are we doing here?  First, replace my nt_username with yours and replace my hostname with yours.  From my less-than-exhaustive trial and error testing, it seems that when either the SSMS Jobs node is expanded or the Job Activity Monitor fetches jobs, two DB calls are made - one to fetch categories and another to fetch jobs.  I tried filtering out the jobs portion originally and that yielded some errors.  So I'm assuming it's trying to marry the categories and the jobs internally, and it expects there to be jobs for each category the first query returned.  By not returning the Report Server category at all, the resulting merged list of jobs doesn't contain any jobs belonging to that category (logically an INNER JOIN).</p>
<p>Sure, this is a dirty hack, but I don't mind.</p>
<p><strong>Update (2012-01-11)</strong><br />
<em>Here is the predicate for hiding those jobs from ALL SSMS clients:</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>96
97
98
99
100
101
102
103
104
105
106
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;">  <span style="color: #0000FF;">SET</span> @where_clause <span style="color: #808080;">+=</span> N<span style="color: #FF0000;">'
  AND
	CASE
		WHEN 
			name = '</span><span style="color: #FF0000;">'Report Server'</span><span style="color: #FF0000;">' 
			AND (
				SELECT program_name 
				FROM sys.sysprocesses 
				where spid = @@spid) = '</span><span style="color: #FF0000;">'Microsoft SQL Server Management Studio'</span><span style="color: #FF0000;">'  THEN 0
		ELSE 1
	END = 1 '</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2012/01/hiding-ssrs-schedule-jobs-in-ssms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SSIS, BIDS and 64bit System DSNs: Who&#8217;s on first?</title>
		<link>http://timlaqua.com/2011/11/ssis-bids-and-64bit-system-dsns-whos-on-first/</link>
		<comments>http://timlaqua.com/2011/11/ssis-bids-and-64bit-system-dsns-whos-on-first/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 20:34:37 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[ssis]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=828</guid>
		<description><![CDATA[After an hour or so of changing settings, package configurations, protection levels, passwords, connection strings, etc - you might just still have yourself one of those dreaded red boxes (and a headache). And you thought inserting data using ODBC was easy... You might even have yourself some logging that indicates an error like this: [AS400 [...]]]></description>
			<content:encoded><![CDATA[<p>After an hour or so of changing settings, package configurations, protection levels, passwords, connection strings, etc - you  might just still have yourself one of those dreaded red boxes (and a headache).  And you thought inserting data using ODBC was easy...</p>
<p><a href="http://timlaqua.com/wp-content/uploads/2011/11/Execute-Package-Failed-To-Acquire-Connection.png"><img src="http://timlaqua.com/wp-content/uploads/2011/11/Execute-Package-Failed-To-Acquire-Connection.png" alt="" title="Execute Package - Failed To Acquire Connection" width="774" height="551" class="alignnone size-full wp-image-833" /></a></p>
<p>You might even have yourself some logging that indicates an error like this:<br />
<strong>[AS400 [19]] Error: ADO NET Destination has failed to acquire the connection {43E6AE37-24E8-46F6-8AB0-689DB6531167}. The connection may have been corrupted.</strong></p>
<p>Assuming you are using a System DSN for your connection (this article is based on an ODBC DSN using the iSeries Access ODBC Driver to write to DB2, but it applies to any ODBC driver with 32bit and 64bit versions where a System DSN is used for the connection).</p>
<p>Before going on, you should understand and have checked the <strong>PackageProtectionLevel</strong> property in your package.  To get any connection that requires a password to run in BIDS, you can't use DontSaveSensitive (unless you're using package configurations to enter the password or an explicit connection string).  This is by far the most common reason connections fail to validate - but there's many resources out there already on that situation, so I won't go in to it.</p>
<p>Now that we know it SHOULD work - why doesn't it?  In short, because you don't have a 64-bit version of the System DSN you selected.  What sense does that make?  Let me show you.<br />
<span id="more-828"></span><br />
<a href="http://timlaqua.com/wp-content/uploads/2011/11/ODBC-Administration-Programs.png"><img src="http://timlaqua.com/wp-content/uploads/2011/11/ODBC-Administration-Programs.png" alt="" title="ODBC Administration Programs" width="202" height="71" class="alignnone size-full wp-image-835" /></a></p>
<p>I'm sure you've all seen this before - which one do we select?  I'm apparently pretty random with it as when I started this investigation, I found various different System DSNs in both places (and they didn't match).  Maybe you just use the Control Panel to get to your ODBC Data Sources:</p>
<p><a href="http://timlaqua.com/wp-content/uploads/2011/11/Data-sources-ODBC-Control-Panel.png"><img src="http://timlaqua.com/wp-content/uploads/2011/11/Data-sources-ODBC-Control-Panel.png" alt="" title="Data sources (ODBC) Control Panel" width="234" height="155" class="alignnone size-full wp-image-831" /></a></p>
<p>Interesting - we know there's two places to manage ODBC connections...  Which one is this?  It's the 64bit one.  Which means if this is the only way you enter System DSNs, all you ever enter are 64bit System DSNs.</p>
<p>Now, on to how this happened in the first place.  First, I'll create both a 64bit DSN and a 32bit DSN:<br />
<a href="http://timlaqua.com/wp-content/uploads/2011/11/ODBC-64bit.png"><img src="http://timlaqua.com/wp-content/uploads/2011/11/ODBC-64bit.png" alt="" title="ODBC 64bit" width="471" height="390" class="alignnone size-full wp-image-841" /></a><br />
<a href="http://timlaqua.com/wp-content/uploads/2011/11/ODBC-32bit.png"><img src="http://timlaqua.com/wp-content/uploads/2011/11/ODBC-32bit.png" alt="" title="ODBC 32bit" width="471" height="390" class="alignnone size-full wp-image-842" /></a></p>
<p>Then in SSIS, we create an ODBC connection, the dropdown lists our DSNs for us like so:</p>
<p><a href="http://timlaqua.com/wp-content/uploads/2011/11/ADO-Connection-Manager-ODBC-32bit-DSN.png"><img src="http://timlaqua.com/wp-content/uploads/2011/11/ADO-Connection-Manager-ODBC-32bit-DSN.png" alt="" title="ADO Connection Manager - ODBC - 32bit DSN" width="608" height="623" class="alignnone size-full wp-image-830" /></a></p>
<p>Notice that these are a mismash of both your User DSNs and 32bit System DSNs (and probably File DSNs... but who uses those anyway).  No 64bit DSNs are listed.  As a side note, this also presents itself when you create a "System DSN" (not knowing you're creating a 64bit specific DSN), then you go in to BIDS and can't find your shiny new DSN in the list.  To get your DSN to show, you probably go back in and create a User DSN, and it will then show up.  Until you try to run it on the server under a different username - which can be even more confusing.</p>
<p>To test if you are encountering this 32/64bit DSN issue, you can change your SSIS Solution properties to use the 32bit runtime:</p>
<p><a href="http://timlaqua.com/wp-content/uploads/2011/11/Debugging-Configuration.png"><img src="http://timlaqua.com/wp-content/uploads/2011/11/Debugging-Configuration.png" alt="" title="Debugging Configuration" width="701" height="425" class="alignnone size-full wp-image-832" /></a></p>
<p>Now run your package again and it should look a little more like this:</p>
<p><a href="http://timlaqua.com/wp-content/uploads/2011/11/Execute-Package-Success-32bit.png"><img src="http://timlaqua.com/wp-content/uploads/2011/11/Execute-Package-Success-32bit.png" alt="" title="Execute Package - Success - 32bit" width="774" height="551" class="alignnone size-full wp-image-834" /></a></p>
<p>You can also take your compiled package and run it with the 32bit version of dtexec and the 64bit version.  Here's what that should look like if you're having this issue:</p>
<p><em>Use the dtexec located under <strong>Program Files\Microsoft SQL Server\100\DTS\Binn</strong></em></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">C:\&gt;&quot;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\dtexec&quot; /FILE &quot;C:\Users\
tlaqua\Documents\Visual Studio 2008\Projects\AS400 ODBC Test\AS400 ODBC Test\bin
\ExportToAS400.dtsx&quot; /CHECKPOINTING OFF  /REPORTING EWCDI
Microsoft (R) SQL Server Execute Package Utility
Version 10.50.2500.0 for 64-bit
Copyright (C) Microsoft Corporation 2010. All rights reserved.
&nbsp;
Started:  12:29:04 PM
Info: 2011-11-18 12:29:04.24
   Code: 0x4004300A
   Source: Export to AS400 SSIS.Pipeline
   Description: Validation phase is beginning.
End Info
Error: 2011-11-18 12:29:05.21
   Code: 0xC0208452
   Source: Export to AS400 AS400 [19]
   Description: ADO NET Destination has failed to acquire the connection {43E6AE
37-24E8-46F6-8AB0-689DB6531167}. The connection may have been corrupted.
End Error
Error: 2011-11-18 12:29:05.21
   Code: 0xC0047017
   Source: Export to AS400 SSIS.Pipeline
   Description: component &quot;AS400&quot; (19) failed validation and returned error code
 0xC0208452.
End Error
Error: 2011-11-18 12:29:05.21
   Code: 0xC004700C
   Source: Export to AS400 SSIS.Pipeline
   Description: One or more component failed validation.
End Error
Error: 2011-11-18 12:29:05.21
   Code: 0xC0024107
   Source: Export to AS400
   Description: There were errors during task validation.
End Error
DTExec: The package execution returned DTSER_FAILURE (1).
Started:  12:29:04 PM
Finished: 12:29:05 PM
Elapsed:  1.029 seconds</pre></div></div>

<p><em>Use the dtexec located under <strong>Program Files<span style="background-color: yellow;"> (x86)</span>\Microsoft SQL Server\100\DTS\Binn</strong></em></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">C:\&gt;&quot;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\dtexec&quot; /FILE &quot;C:\
Users\tlaqua\Documents\Visual Studio 2008\Projects\AS400 ODBC Test\AS400 ODBC Te
st\bin\ExportToAS400.dtsx&quot; /CHECKPOINTING OFF  /REPORTING EWCDI
Microsoft (R) SQL Server Execute Package Utility
Version 10.50.2500.0 for 32-bit
Copyright (C) Microsoft Corporation 2010. All rights reserved.
&nbsp;
Started:  12:29:49 PM
Info: 2011-11-18 12:29:49.96
   Code: 0x4004300A
   Source: Export to AS400 SSIS.Pipeline
   Description: Validation phase is beginning.
End Info
Info: 2011-11-18 12:29:51.14
   Code: 0x4004300A
   Source: Export to AS400 SSIS.Pipeline
   Description: Validation phase is beginning.
End Info
Info: 2011-11-18 12:29:51.41
   Code: 0x40043006
   Source: Export to AS400 SSIS.Pipeline
   Description: Prepare for Execute phase is beginning.
End Info
Info: 2011-11-18 12:29:51.58
   Code: 0x40043007
   Source: Export to AS400 SSIS.Pipeline
   Description: Pre-Execute phase is beginning.
End Info
Info: 2011-11-18 12:29:51.94
   Code: 0x4004300C
   Source: Export to AS400 SSIS.Pipeline
   Description: Execute phase is beginning.
End Info
DataFlow: 2011-11-18 12:29:51.94
   Source: Export to AS400
   Component &quot;AS400&quot; (19) will receive 2 rows on input &quot;ADO NET Destination Inpu
t&quot; (22)
End DataFlow
DataFlow: 2011-11-18 12:29:52.11
   Source: Export to AS400
   Component &quot;AS400&quot; (19) was given end of rowset on input &quot;ADO NET Destination
Input&quot; (22)
End DataFlow
DataFlow: 2011-11-18 12:29:52.11
   Source: Export to AS400
   Component &quot;AS400&quot; (19) will receive 0 rows on input &quot;ADO NET Destination Inpu
t&quot; (22)
End DataFlow
Info: 2011-11-18 12:29:52.11
   Code: 0x40043008
   Source: Export to AS400 SSIS.Pipeline
   Description: Post Execute phase is beginning.
End Info
Info: 2011-11-18 12:29:52.14
   Code: 0x4004300B
   Source: Export to AS400 SSIS.Pipeline
   Description: &quot;component &quot;AS400&quot; (19)&quot; wrote 2 rows.
End Info
Info: 2011-11-18 12:29:52.14
   Code: 0x40043009
   Source: Export to AS400 SSIS.Pipeline
   Description: Cleanup phase is beginning.
End Info
DTExec: The package execution returned DTSER_SUCCESS (0).
Started:  12:29:49 PM
Finished: 12:29:52 PM
Elapsed:  2.574 seconds</pre></div></div>

<p>So how do we avoid/fix this?</p>
<ol>
<li>Ensure you setup the EXACT same System DSNs in both 64bit and 32bit on your development machine.
<li>On your server(s), you most likely only need to setup the 64bit DSNs as all they do is execute via dtexec and it probably uses the 64bit dtexec by default.
<li>If you plan on opening BIDS on your server - refer to point 1 for the server as well because if you run BIDS on it, it's a development box.
<li>Avoid User DSNs.  While they are kind of magic (they don't differentiate between the 64bit and 32bit administration tool - there's only ONE list of User DSNs), they are a formula for headaches on shared development machines, packages ran by the sql server agent, or packages run via scheduled task (all depending on what user context you have setup on each engine).
<li>If you can't setup 64bit System DSNs and have to use 32-bit System DSNs, ensure you have your BIDS solution set to use the 32bit runtime, ensure when you run the packages using dtexec, you use the 32bit version, and when you execute the package via SQL Server Agent, configure it for 32bit execution:
<p><a href="http://timlaqua.com/wp-content/uploads/2011/11/SQL-Server-Agent-Package-Execution-Options.png"><img src="http://timlaqua.com/wp-content/uploads/2011/11/SQL-Server-Agent-Package-Execution-Options.png" alt="" title="SQL Server Agent - Package Execution Options" width="493" height="408" class="alignnone size-full wp-image-836" /></a>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/11/ssis-bids-and-64bit-system-dsns-whos-on-first/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitoring and Starting Data Collector Sets with Powershell</title>
		<link>http://timlaqua.com/2011/10/monitoring-and-starting-data-collector-sets-with-powershell/</link>
		<comments>http://timlaqua.com/2011/10/monitoring-and-starting-data-collector-sets-with-powershell/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 01:33:24 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=801</guid>
		<description><![CDATA[I figure it's about time I posted an update to my previous post on Monitoring, Starting, and Stopping Perfmon Performance Counter Logs using VBScript. In the years since that post, a few operating systems came out and many much more interesting languages happened by. So this update is in Powershell. You could do it in [...]]]></description>
			<content:encoded><![CDATA[<p>I figure it's about time I posted an update to my previous post on <a href="http://timlaqua.com/2008/11/monitoring-starting-and-stopping-perfmon-performance-counter-logs-using-vbscript/" title="Monitoring, Starting, and Stopping Perfmon Performance Counter Logs using VBScript">Monitoring, Starting, and Stopping Perfmon Performance Counter Logs using VBScript</a>.  In the years since that post, a few operating systems came out and many much more interesting languages happened by.  So this update is in Powershell.  You could do it in pretty much any language, but Powershell seems to be my weapon of choice lately.</p>
<p>The basic premise here is that we want our Data Collector Sets to always be running.  Seems like a reasonable request, but for various reasons, Data Collector Sets just... stop.  This script should be run regularly (every 5 minutes?) to ensure that the sets keep collecting data.  In the event that the script finds some work to do, it will send you an email.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#======= START Config ========</span>
<span style="color: #800080;">$emailServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;1.2.3.4&quot;</span>;
<span style="color: #800080;">$fromAddress</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;you@yourcompany.com&quot;</span>;
<span style="color: #800080;">$toAddress</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;you@yourcompany.com&quot;</span>;
<span style="color: #800080;">$ignorePattern</span> <span style="color: pink;">=</span> <span style="color: #800000;">'^(RandomCollectorSet|OSTest)$'</span>;
<span style="color: #008000;">#======== END Config =========</span>
&nbsp;
<span style="color: #800080;"><span style="color: #000080;">$Error</span>ActionPreference</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SilentlyContinue&quot;</span>
<span style="color: #800080;">$serverName</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> env:computername;
<span style="color: #800080;">$emailBody</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>
&nbsp;
<span style="color: #800080;">$collectors</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: pink;">-</span>COM Pla.DataCollectorSetCollection;
<span style="color: #800080;">$collectors</span>.GetDataCollectorSets<span style="color: #000000;">&#40;</span><span style="color: #800080;">$null</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Service\*&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #800080;">$collectors</span>._NewEnum <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Status <span style="color: #FF0000;">-ne</span> <span style="color: #000000;">1</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Name <span style="color: #FF0000;">-notmatch</span> <span style="color: #800080;">$ignorePattern</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span>
	<span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Start<span style="color: #000000;">&#40;</span><span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Status <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$emailBody</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;Started $($_.Name)<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span>
	<span style="color: #000000;">&#125;</span> <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$emailBody</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;Failed to start $($_.Name)<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>;
&nbsp;
<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailBody</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #800080;">$smtp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Net.Mail.SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailServer</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span>
    <span style="color: #800000;">&quot;$serverName &lt;$fromAddress&gt;&quot;</span><span style="color: pink;">,</span> 
    <span style="color: #800080;">$toAddress</span><span style="color: pink;">,</span> 
    <span style="color: #800000;">&quot;Started Data Collector Set(s)&quot;</span><span style="color: pink;">,</span> 
    <span style="color: #800080;">$emailBody</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>If you want the script to keep any of the non-user created collectors running, modify the namespace parameter of the GetDataCollectorSets method call.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/10/monitoring-and-starting-data-collector-sets-with-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pattern for Conditionally Sending SSRS Subscriptions</title>
		<link>http://timlaqua.com/2011/10/pattern-for-conditionally-sending-ssrs-subscriptions/</link>
		<comments>http://timlaqua.com/2011/10/pattern-for-conditionally-sending-ssrs-subscriptions/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 20:51:34 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[ssrs]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=768</guid>
		<description><![CDATA[This is a pretty common request - send the report if there's an issue, don't send it if there's not an issue. This is a simple pattern for doing that using Data Driven Subscriptions. Here, we're not using the data driven subscription to dynamically populate recipient and parameter information, we're just using it to suppress [...]]]></description>
			<content:encoded><![CDATA[<p>This is a pretty common request - send the report if there's an issue, don't send it if there's not an issue.  This is a simple pattern for doing that using Data Driven Subscriptions.  Here, we're not using the data driven subscription to dynamically populate recipient and parameter information, we're just using it to suppress the sending of the report if the report has no value.</p>
<p>To do this, we only need one thing - a query that returns one row if the report should be sent and zero rows if the report should not be sent.  Here is an example - Let's say I want to send a report out if a JDE Address Book record with an AT1 of 'DC' has been updated after a certain julian date.</p>
<p>First, write a query to return rows meeting that criteria:<span id="more-768"></span></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> LIB.<span style="color: #202020;">F0101</span>
<span style="color: #0000FF;">WHERE</span> ABAT1 <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DC'</span>
	<span style="color: #808080;">AND</span> ABUPMJ <span style="color: #808080;">&gt;=</span> <span style="color: #000;">111292</span></pre></div></div>

<p>That's great, but it can return multiple rows...  So just select the first record (because all we care about is if we have one or more than one - exactly how many is irrelevant).  We also don't care what the column values are, so just select some arbitrary value.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">TOP</span> <span style="color: #000;">1</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">AS</span> DoStuff
<span style="color: #0000FF;">FROM</span> LIB.<span style="color: #202020;">F0101</span>
<span style="color: #0000FF;">WHERE</span> ABAT1 <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DC'</span>
	<span style="color: #808080;">AND</span> ABUPMJ <span style="color: #808080;">&gt;=</span> <span style="color: #000;">111292</span></pre></div></div>

<p>So now we have what we need in SQL - let me add one final note on this for those DB2 users out there.  DB2 doesn't understand "TOP" so we have to use their syntax, FETCH FIRST (and likewise for MySQL, use LIMIT).</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">AS</span> DoStuff
<span style="color: #0000FF;">FROM</span> LIB.<span style="color: #202020;">F0101</span>
<span style="color: #0000FF;">WHERE</span> ABAT1 <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DC'</span>
	<span style="color: #808080;">AND</span> ABUPMJ <span style="color: #808080;">&gt;=</span> <span style="color: #000;">111292</span>
<span style="color: #0000FF;">FETCH</span> <span style="color: #0000FF;">FIRST</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">ROWS</span> <span style="color: #0000FF;">ONLY</span></pre></div></div>

<p>Now, you're ready to create your subscription.</p>
<h6>Go in to your report Subscriptions and click on the New Data Driven Subscription button</h6>
<p><a style="padding-left: 3px; border-left: 5px solid #bbbbbb; display: block;" href="http://timlaqua.com/wp-content/uploads/2011/10/DataDrivenSubscriptionButton.png"><img src="http://timlaqua.com/wp-content/uploads/2011/10/DataDrivenSubscriptionButton.png" alt="" title="DataDrivenSubscriptionButton" width="482" height="31" class="alignnone size-full wp-image-771" /></a></p>
<h6>Enter meaningful name and select Shared Data Source</h6>
<p><a style="padding-left: 3px; border-left: 5px solid #bbbbbb; display: block;" href="http://timlaqua.com/wp-content/uploads/2011/10/Step1-GeneralOptions.png"><img src="http://timlaqua.com/wp-content/uploads/2011/10/Step1-GeneralOptions.png" alt="" title="Step1-GeneralOptions" width="660" height="308" class="alignnone size-full wp-image-772" /></a><br />
<em>* If you don't use shared data sources - you should <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </em></p>
<h6>Select Shared Data Source</h6>
<p><a style="padding-left: 3px; border-left: 5px solid #bbbbbb; display: block;" href="http://timlaqua.com/wp-content/uploads/2011/10/Step2-DataSource.png"><img src="http://timlaqua.com/wp-content/uploads/2011/10/Step2-DataSource.png" alt="" title="Step2-DataSource" width="491" height="99" class="alignnone size-full wp-image-773" /></a><br />
<em>* I really hope you don't have a shared data source called "local" - this is just an example</em></p>
<h6>Enter query we developed above</h6>
<p><a style="padding-left: 3px; border-left: 5px solid #bbbbbb; display: block;" href="http://timlaqua.com/wp-content/uploads/2011/10/Step3-Query.png"><img src="http://timlaqua.com/wp-content/uploads/2011/10/Step3-Query.png" alt="" title="Step3-Query" width="629" height="530" class="alignnone size-full wp-image-774" /></a></p>
<h6>Enter the usual options - all static values</h6>
<p><a style="padding-left: 3px; border-left: 5px solid #bbbbbb; display: block;" href="http://timlaqua.com/wp-content/uploads/2011/10/Step4-SubscriptionOptions.png"><img src="http://timlaqua.com/wp-content/uploads/2011/10/Step4-SubscriptionOptions.png" alt="" title="Step4-SubscriptionOptions" width="574" height="537" class="alignnone size-full wp-image-775" /></a></p>
<h6>Enter parameters - usually just "Use Default"</h6>
<p><a style="padding-left: 3px; border-left: 5px solid #bbbbbb; display: block;" href="http://timlaqua.com/wp-content/uploads/2011/10/Step5-Parameters.png"><img src="http://timlaqua.com/wp-content/uploads/2011/10/Step5-Parameters.png" alt="" title="Step5-Parameters" width="546" height="210" class="alignnone size-full wp-image-776" /></a><br />
<em>* This is one drawback to the pattern, you have to type in your parameter(s) - no dropdowns here if you're not using the default</em></p>
<h6>Select your schedule type</h6>
<p><a style="padding-left: 3px; border-left: 5px solid #bbbbbb; display: block;" href="http://timlaqua.com/wp-content/uploads/2011/10/Step6-ChooseSchedule.png"><img src="http://timlaqua.com/wp-content/uploads/2011/10/Step6-ChooseSchedule.png" alt="" title="Step6-ChooseSchedule" width="488" height="137" class="alignnone size-full wp-image-777" /></a></p>
<h6>And finally the usual timed schedule options</h6>
<p><a style="padding-left: 3px; border-left: 5px solid #bbbbbb; display: block;" href="http://timlaqua.com/wp-content/uploads/2011/10/Step7-DefineSchedule.png"><img src="http://timlaqua.com/wp-content/uploads/2011/10/Step7-DefineSchedule.png" alt="" title="Step7-DefineSchedule" width="520" height="541" class="alignnone size-full wp-image-778" /></a></p>
<p>The schedule you specify will be both the time when the above query is executed to see if the report should be sent as well as the time the report will be sent out (assuming it should be sent out).  As far as who the report is sent to, 99% of the time this should be a distribution list that can be managed elsewhere.  You don't want to be wading through SSRS to update the list of subscribed users (unless you're the only subscribed user... then go ahead).</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/10/pattern-for-conditionally-sending-ssrs-subscriptions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Script for Ad-Hoc SSRS TimedSubscription Scheduling</title>
		<link>http://timlaqua.com/2011/10/script-for-ad-hoc-ssrs-timedsubscription-scheduling/</link>
		<comments>http://timlaqua.com/2011/10/script-for-ad-hoc-ssrs-timedsubscription-scheduling/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 19:16:04 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[ssrs]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=754</guid>
		<description><![CDATA[Quick script to locate and execute SSRS timed subscriptions (useful for testing). 1. Execute the top (uncommented) part and identify which subscription you want to schedule. 2. Paste the SubscriptionId from that row in to the @id variable in the lower section 3. Run the entire lower (commented) section DECLARE @ReportName VARCHAR&#40;255&#41; = 'Report Name' [...]]]></description>
			<content:encoded><![CDATA[<p>Quick script to locate and execute SSRS timed subscriptions (useful for testing).</p>
<p>1. Execute the top (uncommented) part and identify which subscription you want to schedule.<br />
2. Paste the SubscriptionId from that row in to the @id variable in the lower section<br />
3. Run the entire lower (commented) section</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">DECLARE</span> @ReportName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Report Name'</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span>
      a.<span style="color: #0000FF;">PATH</span>
      ,b.<span style="color: #202020;">SubscriptionID</span> 
      ,b.<span style="color: #202020;">Description</span>
      ,<span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>b.<span style="color: #0000FF;">PARAMETERS</span> <span style="color: #0000FF;">AS</span> XML<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">PARAMETERS</span><span style="color: #808080;">&#93;</span>
      ,b.<span style="color: #202020;">LastRunTime</span>
      ,b.<span style="color: #202020;">LastStatus</span>
      ,<span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>b.<span style="color: #202020;">ExtensionSettings</span> <span style="color: #0000FF;">AS</span> XML<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>ExtensionSettings<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> ReportServer.<span style="color: #202020;">dbo</span>.<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">CATALOG</span><span style="color: #808080;">&#93;</span> a
      <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> ReportServer.<span style="color: #202020;">dbo</span>.<span style="color: #808080;">&#91;</span>Subscriptions<span style="color: #808080;">&#93;</span> b
            <span style="color: #0000FF;">ON</span> b.<span style="color: #202020;">Report_OID</span> <span style="color: #808080;">=</span> a.<span style="color: #202020;">ItemID</span>
<span style="color: #0000FF;">WHERE</span> a.<span style="color: #202020;">Name</span> <span style="color: #808080;">=</span> @ReportName
&nbsp;
<span style="color: #008080;">/*
DECLARE 
       @id varchar(260) = ''
      ,@Type VARCHAR(32)                  = 'TimedSubscription'
&nbsp;
EXEC [ReportServer].dbo.AddEvent @EventType=@Type, @EventData=@id
&nbsp;
*/</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/10/script-for-ad-hoc-ssrs-timedsubscription-scheduling/feed/</wfw:commentRss>
		<slash:comments>0</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>
	</channel>
</rss>

