<?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>Michael J. Swart</title>
	<atom:link href="http://michaeljswart.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://michaeljswart.com</link>
	<description>Database Whisperer</description>
	<lastBuildDate>Wed, 15 Feb 2012 18:34:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Careful Hashing</title>
		<link>http://michaeljswart.com/2012/02/careful-hashing/</link>
		<comments>http://michaeljswart.com/2012/02/careful-hashing/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 17:00:28 +0000</pubDate>
		<dc:creator>Michael J. Swart</dc:creator>
				<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Technical Articles]]></category>
		<category><![CDATA["sql server"]]></category>
		<category><![CDATA[encodings]]></category>
		<category><![CDATA[hash functions]]></category>
		<category><![CDATA[hashbytes]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[sha1]]></category>

		<guid isPermaLink="false">http://michaeljswart.com/?p=2542</guid>
		<description><![CDATA[Cryptographic hashing functions like MD5 or SHA-1 are examples of one-way functions that take any data you give it and return a fixed set of bytes.]]></description>
			<content:encoded><![CDATA[<p>Cryptographic hashing functions like <a href="http://en.wikipedia.org/wiki/MD5">MD5 </a>or <a href="http://en.wikipedia.org/wiki/SHA-1">SHA-1</a> are examples of one-way functions that take any data you give it and return a fixed set of bytes (for example, 16 bytes for MD5 and 20 bytes for SHA-1). </p>
<p>I recently had trouble coming up with the same hash value for what I thought were the exact same inputs. Compare the following two examples:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// C# example</span>
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> byteArray <span style="color: #008000;">=</span> Encoding<span style="color: #008000;">.</span><span style="color: #0000FF;">Unicode</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;I'm a lumberjack and I'm okay.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
SHA1 sha <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SHA1CryptoServiceProvider<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> hashedPasswordBytes <span style="color: #008000;">=</span> sha<span style="color: #008000;">.</span><span style="color: #0000FF;">ComputeHash</span><span style="color: #008000;">&#40;</span>byteArray<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span>hashedPasswordBytes<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//30-F1-CE-3E-7E-1F-17-27-A7-B5-97-39-44-D0-FE-EA-DA-69-53-2B</span></pre></div></div>

<p>That&#8217;s different than this:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- SQL example</span>
<span style="color: #0000FF;">select</span> HASHBYTES<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SHA1'</span>, <span style="color: #FF0000;">'I'</span><span style="color: #FF0000;">'m a lumberjack and I'</span><span style="color: #FF0000;">'m okay.'</span><span style="color: #808080;">&#41;</span>
<span style="color: #008080;">--0x4D6936CEDD0DE794AC86F9A4099DCBB4EFED8E1F</span></pre></div></div>

<p>So what gives? Before reading any further, can you spot the problem? In both examples above, two things are happening. First a string of characters is being converted into a string of bytes and then that string of bytes gets hashed. I&#8217;ve learned that it&#8217;s not the hash function that&#8217;s the problem, it&#8217;s converting the character string into binary that is inconsistent.</p>
<p><img src="http://michaeljswart.com/wp-content/uploads/2012/02/catscradle.png" alt="" title="Cat&#039;s cradle always makes me think of that song... Hmm... I&#039;m going to go play with my kids now." width="500" height="300" class="alignnone size-full wp-image-2545" /></p>
<h3>String Conversions</h3>
<p>Maybe that&#8217;s not surprising, but still, it&#8217;s one more thing to be careful about: converting <em>strings to bytes</em>. SQL Server&#8217;s wide characters (NCHARs and NVARCHARs) are equivalent to .Net&#8217;s <a href="http://msdn.microsoft.com/en-us/library/system.text.encoding.unicode.aspx">Encoding.Unicode</a> and SQL Server&#8217;s single non-unicode characters (CHAR and VARCHAR) (single-byte characters) are equivalent to .net&#8217;s <a href="http://msdn.microsoft.com/en-us/library/system.text.encoding.ascii.aspx">Encoding.ASCII</a>.</p>
<p>So for completeness sake, these should be equivalent:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- wide characters (remember unicode string literals are prefixed with 'N')</span>
<span style="color: #0000FF;">select</span> HASHBYTES<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SHA1'</span>, N<span style="color: #FF0000;">'I'</span><span style="color: #FF0000;">'m a lumberjack and I'</span><span style="color: #FF0000;">'m okay.'</span><span style="color: #808080;">&#41;</span>
<span style="color: #008080;">--0x30F1CE3E7E1F1727A7B5973944D0FEEADA69532B</span>
&nbsp;
<span style="color: #008080;">-- non-unicode characters:</span>
<span style="color: #0000FF;">select</span> HASHBYTES<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SHA1'</span>, <span style="color: #FF0000;">'I'</span><span style="color: #FF0000;">'m a lumberjack and I'</span><span style="color: #FF0000;">'m okay.'</span><span style="color: #808080;">&#41;</span>
<span style="color: #008080;">--0x4D6936CEDD0DE794AC86F9A4099DCBB4EFED8E1F</span></pre></div></div>

<p>And</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Unicode</span>
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> byteArray <span style="color: #008000;">=</span> Encoding<span style="color: #008000;">.</span><span style="color: #0000FF;">Unicode</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;I'm a lumberjack and I'm okay.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
SHA1 sha <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SHA1CryptoServiceProvider<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> hashedPasswordBytes <span style="color: #008000;">=</span> sha<span style="color: #008000;">.</span><span style="color: #0000FF;">ComputeHash</span><span style="color: #008000;">&#40;</span>byteArray<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span>hashedPasswordBytes<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//30-F1-CE-3E-7E-1F-17-27-A7-B5-97-39-44-D0-FE-EA-DA-69-53-2B</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//ASCII</span>
byteArray <span style="color: #008000;">=</span> Encoding<span style="color: #008000;">.</span><span style="color: #0000FF;">ASCII</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;I'm a lumberjack and I'm okay.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
hashedPasswordBytes <span style="color: #008000;">=</span> sha<span style="color: #008000;">.</span><span style="color: #0000FF;">ComputeHash</span><span style="color: #008000;">&#40;</span>byteArray<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span>hashedPasswordBytes<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//4D-69-36-CE-DD-0D-E7-94-AC-86-F9-A4-09-9D-CB-B4-EF-ED-8E-1F</span></pre></div></div>

<p>This means that if you&#8217;re going to hash strings in SQL Server and compare them to strings that are hashed in C#, you want to use</p>
<ul>
<li>Encoding.Unicode for NCHARS and NVARCHARS</li>
<li>Encoding.ASCII for CHARS and VARCHARS</li>
</ul>
<p>This also means that for <em>this</em> use case, I wouldn&#8217;t feel safe using other encodings (such as <a href="http://msdn.microsoft.com/en-us/library/system.text.encoding.utf8.aspx">Encoding.UTF8</a>) because SQL Server can&#8217;t duplicate that string to binary conversion.</p>
<h3>Caveats</h3>
<ul>
<li>Don&#8217;t trust me and test it out for yourself!</li>
<li>Collations matter a little (sort order is not relevant here). The code page for your SQL Server collation should match the code page of the .net encoding when dealing with single byte characters. Unicode strings should not care about collation.</li>
<li>If you do find any counter-examples for anything I&#8217;ve written here, let me know in the comments.</li>
]]></content:encoded>
			<wfw:commentRss>http://michaeljswart.com/2012/02/careful-hashing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Microsoft Model Databases: Some Unconventional Alternatives?</title>
		<link>http://michaeljswart.com/2012/02/microsoft-model-databases-some-unconventional-alternatives/</link>
		<comments>http://michaeljswart.com/2012/02/microsoft-model-databases-some-unconventional-alternatives/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 01:53:12 +0000</pubDate>
		<dc:creator>Michael J. Swart</dc:creator>
				<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Technical Articles]]></category>

		<guid isPermaLink="false">http://michaeljswart.com/?p=2520</guid>
		<description><![CDATA[It seems like Microsoft has always provided example databases in order to illustrate database concepts. Pubs: Back when SQL Server 2000 was new, Microsoft provided this sample database and maybe you remember it. Pubs was a really simple database that was designed to represent data that a fictional book publishing company might use. The database [...]]]></description>
			<content:encoded><![CDATA[<p>It seems like Microsoft has always provided example databases in order to illustrate database concepts.</p>
<p><strong>Pubs</strong>: Back when SQL Server 2000 was new, Microsoft provided this sample database and maybe you remember it. Pubs was a really simple database that was designed to represent data that a fictional book publishing company might use. The database had a name (pubs) but I don&#8217;t think anyone ever gave the company a name. From <a href="http://msdn.microsoft.com/en-us/library/aa238305(v=SQL.80).aspx">here</a> we&#8217;re told that it was &#8220;used to demonstrate many of the options available&#8221; for SQL Server.</p>
<p><strong>Northwind</strong> also was available for SQL Server 2000. It was a database that was used for a fictitious company &#8220;Northwind Traders&#8221;. The company &#8220;<a href="http://msdn.microsoft.com/en-us/library/aa276825(v=sql.80).aspx">imports and exports specialty foods from around the world</a>.&#8221; It was better than pubs, but that wasn&#8217;t saying much. Pubs set a pretty low bar.</p>
<p><strong>AdventureWorks</strong>: The Adventureworks database came along with SQL Server 2005 and we were introduced to the bicycle manufacturer Adventure Works Cycle. The database was pretty comprehensive and it touched on a lot more features of SQL Server. I&#8217;ve seen countless performance demos that query <a title="just google it" href="Sales.SalesOrderDetail performance">Sales.SalesOrderDetail</a>. There&#8217;s even an Adventureworks Data Warehouse, an Adventureworks OLAP cube and even a light version: <a href="http://msftdbprodsamples.codeplex.com/">AdventureworksLT</a>.</p>
<p><strong>Contoso</strong> And lately there&#8217;s a new sample database Contoso. It&#8217;s another fictional retail company (<a href="http://en.wikipedia.org/wiki/Contoso">Contoso Ltd.</a> This time they&#8217;re selling electronics and appliances). This database is used for Business Intelligence demos. With Contoso, Microsoft has developed and made a data warehouse and an SSAS cube available.</p>
<p>Presumably, each of these databases is an example of Microsoft putting their best foot forward. Or at least it&#8217;s a database which enables them to show off what their database software can do.</p>
<p><img class="alignnone size-full wp-image-2526" title="I need new boots" src="http://michaeljswart.com/wp-content/uploads/2012/02/bestfoot.png" alt="" width="500" height="300" /></p>
<h3>Beyond Demos</h3>
<p>So those databases are good for demos.</p>
<p>But if we&#8217;re looking for other Microsoft-designed databases, we don&#8217;t have to stop there. There&#8217;s other ones that we can look at. I&#8217;m talking about the databases that Microsoft ships along with their products. When looking at these, remember:</p>
<ul>
<li><strong>There are some <em>good </em>examples, &#8230;</strong><br />
We can look at those databases and see how they&#8217;re constructed. If you see some interesting db designs, you can use that.</li>
<li><strong>&#8230; and there are some <em>not</em> so good examples &#8230;</strong><br />
These databases weren&#8217;t built as database role models. So there&#8217;s bound to be a lot of database design choices that are not ideal. I know that Microsoft has huge pressure to maintain backwards compatibility.</li>
<li><strong>&#8230; and that&#8217;s okay.</strong><br />
It&#8217;s actually a fun exercise to pick out the good designs from the bad. It&#8217;s like a smorgasbord, you take the lessons you like and leave the rest.</li>
</ul>
<p>Some examples of what I&#8217;m talking about.</p>
<h3>ReportServer</h3>
<p>Install and configure an instance of SQL Server Reporting Services. Take a look at the ReportServer. It&#8217;s a pretty nice database schema. One thing that was interesting was the choice of identity column data types:</p>
<ul>
<li><strong>Catalog</strong> seems to be one of the main tables here and they&#8217;re using uniqueidentifiers (GUIDs) for identity columns. Normally people scoff at that, but I think it makes sense <em>in this case</em>. Catalog is the table that tracks reports, datasources and folder structures. Even at it&#8217;s largest, it can&#8217;t be that big (I just checked my own installation and the clustered index fits on 1 extent). That means that all the worries about GUIDs for primary keys are mitigated and the choice of using a globally unique identifier might make sense here.</li>
<li><strong>ExecutionLogStorage </strong>Contrast that with ReportServer&#8217;s largest table, ExecutionLogStorage. Depending on how busy your Reporting Services installation is, this table can grow very large with one row for every report view. When I look at the choice for their primary key, I see that it&#8217;s clustered index on a single BIGINT column defined as it&#8217;s IDENTITY column. Well done.</li>
</ul>
<h3>Any Database&#8217;s Metadata</h3>
<ul>
<li>I like the object oriented influence here:</li>
<ul>
<li>The relationship between sys.objects &#8211;&gt; sys.tables and between sys.objects &#8211;&gt; sys.procedures is the <a href="http://en.wikipedia.org/wiki/Subtyping">subtype </a>relationship <em><strong>class &#8211;&gt; subclass</strong>. </em>And that shows in the schema, for example, there&#8217;s one sys.object row for every sys.table row.</li>
<li>The relationship between sys.foreign_keys &#8211;&gt; and sys.foreign_key_columns is the <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> relationship. And that also shows in the schema too. The &#8220;primary key&#8221; for the table foreign_key_columns is (constraint_object_id, constraint_column_id) and it contains the primary key of its owner.</li>
</ul>
<li>Another good example is the sys.index_columns table. Look at the schema diagram below. It&#8217;s a perfect instance of my <a href="http://michaeljswart.com/2011/04/data-modelling-my-favourite-example/">favourite DB Design example</a></li>
</ul>
<p style="padding-left: 30px;"><a href="http://michaeljswart.com/2011/04/data-modelling-my-favourite-example/"><img class="size-full wp-image-2528" title="click through to my favourite data modelling example." src="http://michaeljswart.com/wp-content/uploads/2012/02/metadata.png" alt="" width="399" height="678" /></a></p>
<h3>Any Sharepoint database</h3>
<ul>
<li>[Sigh] These are mostly counter-examples here, I took a brief glance at the schema once and decided quickly that there are no good lessons. Can anyone tell me if that&#8217;s changed?</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://michaeljswart.com/2012/02/microsoft-model-databases-some-unconventional-alternatives/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Removing Duplicate Dimension Rows in SSIS</title>
		<link>http://michaeljswart.com/2012/02/removing-duplicate-dimension-rows-in-ssis/</link>
		<comments>http://michaeljswart.com/2012/02/removing-duplicate-dimension-rows-in-ssis/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 09:00:39 +0000</pubDate>
		<dc:creator>Michael J. Swart</dc:creator>
				<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Technical Articles]]></category>
		<category><![CDATA[Business Intelligence]]></category>
		<category><![CDATA[data flow]]></category>
		<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://michaeljswart.com/?p=2490</guid>
		<description><![CDATA[I want a data flow transformation which removes duplicate key values.]]></description>
			<content:encoded><![CDATA[<p><H3>Something New For Me</H3><br />
I&#8217;m relatively new to SQL Server Integration Services (SSIS). And so I want to explain how I solved a problem and invite Business Intelligence (BI) experts (and wannabe experts) to comment or point out things that I missed. </p>
<h3>A Short Description of the Problem</h3>
<p>So here&#8217;s a short description of the problem I&#8217;m trying to solve. It involves populating a dimension table. <strong>I want a data flow transformation which removes duplicate key values.</strong> In other words, every time I come across a new key value for a dimension, I want to pass through that entire row (not just the key values). This is kind of like a cross between T-SQL&#8217;s <a href="http://msdn.microsoft.com/en-us/library/ms176104(v=sql.110).aspx">DISTINCT</a> and <a href="http://msdn.microsoft.com/en-us/library/hh213018(v=sql.110).aspx">FIRST_VALUE</a>.</p>
<p><img src="http://michaeljswart.com/wp-content/uploads/2012/01/First.png" alt="" title="Congratulations, you&#039;re are newest dimension member" width="500" height="300" class="alignnone size-full wp-image-2489" /></p>
<p>I found out recently that people have treated this topic before:
<ul>
<li><a href="http://social.msdn.microsoft.com/Forums/en/sqlintegrationservices/thread/8cf43f36-0e1e-4be1-b1cc-0661d8afbdd0">Find Duplicate Rows and select 1 of them</a></li>
<li>And <a href="http://toddmcdermid.blogspot.com/2009/01/extracting-duplicate-primary-key-rows.html">Eliminating Duplicate Primary Keys in SSIS</a></li>
</ul>
<p>But because of my bad luck, I only found these posts <em>after</em> I muddled through a solution. But I was surprised to find out my solution had some interesting differences.</p>
<h3>The Setup</h3>
<p>First I&#8217;ll explain my situation. Say I&#8217;ve got a flat file containing data about Prime Ministers:</p>
<p><div id="attachment_2493" class="wp-caption alignnone" style="width: 561px"><a href="http://en.wikipedia.org/wiki/List_of_Prime_Ministers_of_Canada"><img src="http://michaeljswart.com/wp-content/uploads/2012/02/PrimeMinisters.png" alt="" title="click through to source (wikipedia.org)" width="551" height="494" class="size-full wp-image-2493" /></a><p class="wp-caption-text">The source data</p></div></p>
<p>My main goal is to use this data to populate a data warehouse. That data warehouse has a schema like this:</p>
<p><div id="attachment_2498" class="wp-caption alignnone" style="width: 405px"><a href="http://michaeljswart.com/wp-content/uploads/2012/02/PMschema.png"><img src="http://michaeljswart.com/wp-content/uploads/2012/02/PMschema.png" alt="" title="The Data Warehouse Schema" width="395" height="276" class="size-full wp-image-2498" /></a><p class="wp-caption-text">The Data Warehouse Schema</p></div></p>
<p>This example is just for illustration. In real life, the number of fact rows is very large, and the number of dimension rows is relatively small. The time dimension will be pre-populated, but I want to load the other dimensions using values from the flat file. So that means I plan to process the data twice: The first time will be to load these dimensions, and the second time will be to load the fact table. When I process the data for dimensions, I :</p>
<ul>
<li>Use a lookup transform to find whether that dimension already exists in the warehouse</li>
<li>Use the <em>No Match Output</em> to identify dimension rows I haven&#8217;t seen before. Those rows will be used to load the dimension. (i.e. I&#8217;m treating the dimension like a <em>Never</em>-Changing-Dimension rather than a Slowly Changing Dimension.)</li>
</ul>
<p>The problem is that these unmatched rows can be duplicated and I don&#8217;t want those duplicate dimensions rows getting into the dimension table.</p>
<h3>Things I considered:</h3>
<ul>
<li>I considered using a staging table on the DB side. But that required too much space, the amount of space needed was comparable to the fact table, not the dimension table.</li>
<li>I also considered inserting into dimensions a row-at-a-time using the MERGE statement on the database side. But I didn&#8217;t consider that for long. The performance with that strategy was so unacceptable.</li>
<li>I could have used a sort/aggregate, but that was a blocking transformation and I really didn&#8217;t need the data sorted.</li>
</ul>
<h3>What I ended up with</h3>
<p>I created a script transform which seems to do the trick for what I want. My Data Flow task looks like this:<br />
<img src="http://michaeljswart.com/wp-content/uploads/2012/02/PMDataFlow.png" alt="" title="The Data Flow" width="518" height="545" class="alignnone size-full wp-image-2496" /></p>
<p>In those script transforms you see up there, I told SSIS that each script will be used to filter rows out or let them pass through. I did that by setting ExclusionGroup to 1 (by default, it&#8217;s normally 0). Here&#8217;s where that&#8217;s done:<br />
<img src="http://michaeljswart.com/wp-content/uploads/2012/02/PMExclusionGroup.png" alt="" title="Specifies that the output filters input rows." width="666" height="580" class="alignnone size-full wp-image-2497" /></p>
<p>Then in the script, I created a list of <em>seen</em> dimensions. And I let rows pass through if they <em>haven&#8217;t</em> yet been seen. The script simply looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Input0_ProcessInputRow<span style="color: #008000;">&#40;</span>Input0Buffer Row<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Row<span style="color: #008000;">.</span><span style="color: #0000FF;">Party_IsNull</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>seenParty<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>Row<span style="color: #008000;">.</span><span style="color: #0000FF;">Party</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        seenParty<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>Row<span style="color: #008000;">.</span><span style="color: #0000FF;">Party</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        Row<span style="color: #008000;">.</span><span style="color: #0000FF;">DirectRowToOutput0</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Logically it behaves exactly the same as the sort transformation (as explained in <a href="http://toddmcdermid.blogspot.com/2009/01/eliminating-duplicate-primary-keys-in.html">&#8220;Dead Easy Duplicate Key Removal&#8221;</a> by Todd McDermid). Except for these things:</p>
<ul>
<li>It seems to perform fast</li>
<li>It&#8217;s not a blocking transformation</li>
<li>But you don&#8217;t get all that for nothing. What we&#8217;re not getting with this method is that the rows aren&#8217;t sorted. In most cases, that doesn&#8217;t matter.</li>
<li>It takes some memory, so you have to be aware of that. Ask yourself, how well can all unseen dimension keys fit in memory?</li>
</ul>
<h3>Some questions for you BI guys</h3>
<p>And here&#8217;s where I&#8217;d like you to chime in.</p>
<ol>
<li>What&#8217;s the most common approach to this problem?</li>
<li>I get the feeling that I could use the Cache Transform for this technique. But I haven&#8217;t tried it.</li>
<li>Are there any new features in SQL 2012 that help?</li>
<li>Am I re-inventing the wheel here?</li>
<li>Am I missing anything else that should be obvious?</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://michaeljswart.com/2012/02/removing-duplicate-dimension-rows-in-ssis/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Rebuild Your Indexes Online (When You Can)</title>
		<link>http://michaeljswart.com/2012/01/rebuild-your-indexes-online-when-you-can/</link>
		<comments>http://michaeljswart.com/2012/01/rebuild-your-indexes-online-when-you-can/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 17:00:41 +0000</pubDate>
		<dc:creator>Michael J. Swart</dc:creator>
				<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Technical Articles]]></category>
		<category><![CDATA["sql server"]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[index rebuild]]></category>
		<category><![CDATA[ONLINE]]></category>
		<category><![CDATA[ONLINE=ON]]></category>
		<category><![CDATA[rebuild]]></category>
		<category><![CDATA[sql server 2012]]></category>

		<guid isPermaLink="false">http://michaeljswart.com/?p=2448</guid>
		<description><![CDATA[Instead of wading through that logic above, just TRY it and let SQL Server figure it out.]]></description>
			<content:encoded><![CDATA[<p><a href="http://michaeljswart.com/wp-content/uploads/2012/01/Form1.cs_.txt"><img src="http://michaeljswart.com/wp-content/uploads/2012/01/OnlineRebuild.png" alt="" title="click to see me draw with code" width="500" height="300" class="alignnone size-full wp-image-2473" /></a></p>
<p>So I was recently reading SQL Server&#8217;s blog, specifically the article <a href="http://blogs.technet.com/b/dataplatforminsider/archive/2012/01/20/customers-using-sql-server-2012-today.aspx">Customers using SQL Server 2012 today!</a> and some brave businesses are already using and enjoying some of SQL Server 2012 features that help their databases stay available. I&#8217;m excited about the new features too. For example, index rebuilds have been improved. We can now rebuild indexes online that include &#8220;blob&#8221; columns (like nvarchar(max), image, etc&#8230;). This means that (almost) every index can be rebuilt without requiring a table lock for the entire operation. And that&#8217;s good news for availability!</p>
<p>This wasn&#8217;t the case in earlier versions. In earlier versions, you couldn&#8217;t rebuild an index online if it included columns that were large strings. If you tried, you would get this message:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">/*
An online operation cannot be performed for index 'ix_t1_1' because the 
index contains column '&lt;column name&gt;' of data type text, ntext, image, varchar(max), 
nvarchar(max), varbinary(max), xml, or large CLR type. For a non-clustered 
index, the column could be an include column of the index. For a clustered 
index, the column could be any column of the table. If DROP_EXISTING is 
used, the column could be part of a new or old index. The operation must be 
performed offline. 
*/</span></pre></div></div>

<h3>Logic to determine when ONLINE=ON is supported</h3>
<p>So that means there&#8217;s one more thing to check when finding out whether you can rebuild an index on-line. The logic now goes like this. You can rebuild an index online if:</p>
<ul>
<li>You&#8217;re using Enterprise Edition or higher</li>
<li>And you&#8217;re using SQL Server 2012 or later</li>
<li>Or you&#8217;re using SQL Server 2008 or earlier</li>
<li>And your index is clustered and the table contains no blob columns</li>
<li>Or your index is non-clustered and the index includes no blob columns</li>
</ul>
<p>Hmm&#8230; You can&#8217;t really put parentheses in a bullet point list. Here try this flow chart:<br />
<div id="attachment_2453" class="wp-caption alignnone" style="width: 510px"><img src="http://michaeljswart.com/wp-content/uploads/2012/01/ONLINE.png" alt="" title="Can you rebuild it online?" width="500" height="400" class="size-full wp-image-2453" /><p class="wp-caption-text">Clear as mud</p></div></p>
<p>Hmm&#8230; that really doesn&#8217;t clear things up too well either. And I haven&#8217;t even mentioned partitioned indexes.</p>
<h3>Just Try It</h3>
<p>Maybe you&#8217;re like me, you may have to deal with multiple versions, multiple editions, and multiple tables and their indexes. Instead of wading through that logic above, just TRY it and let SQL Server figure it out. Here&#8217;s a sproc which takes a table name and index name and tries to rebuild the index online. If it can&#8217;t, it builds it offline.</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;">procedure</span> s_TryRebuildOnlineOtherwiseOffline
<span style="color: #808080;">&#40;</span>
	@<span style="color: #0000FF;">schema</span> sysname <span style="color: #808080;">=</span> <span style="color: #FF0000;">'dbo'</span>,
	@tablename sysname,
	@indexname sysname
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">as</span>
<span style="color: #0000FF;">begin</span>
	<span style="color: #0000FF;">set</span> @<span style="color: #0000FF;">schema</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>@<span style="color: #0000FF;">schema</span><span style="color: #808080;">&#41;</span>;
	<span style="color: #0000FF;">set</span> @tablename <span style="color: #808080;">=</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>@tablename<span style="color: #808080;">&#41;</span>;
	<span style="color: #0000FF;">set</span> @indexname <span style="color: #808080;">=</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>@indexname<span style="color: #808080;">&#41;</span>;
&nbsp;
	<span style="color: #0000FF;">declare</span> @sqlRebuild <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">set</span> @sqlRebuild <span style="color: #808080;">=</span> N<span style="color: #FF0000;">'ALTER INDEX '</span> <span style="color: #808080;">+</span> @indexname <span style="color: #808080;">+</span> <span style="color: #FF0000;">' ON '</span> <span style="color: #808080;">+</span> @<span style="color: #0000FF;">schema</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.'</span> <span style="color: #808080;">+</span> @tablename <span style="color: #808080;">+</span> <span style="color: #FF0000;">' REBUILD'</span>;
	<span style="color: #0000FF;">declare</span> @sqlRebuildOnline <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">set</span> @sqlRebuildOnline <span style="color: #808080;">=</span> @sqlRebuild <span style="color: #808080;">+</span> <span style="color: #FF0000;">' WITH (ONLINE=ON)'</span>;
&nbsp;
	<span style="color: #0000FF;">begin</span> try
		<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span> @sqlRebuildOnline;
		<span style="color: #0000FF;">print</span> @sqlRebuildOnline;
	<span style="color: #0000FF;">end</span> try
	<span style="color: #0000FF;">begin</span> catch
		<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span> @sqlRebuild;
		<span style="color: #0000FF;">print</span> @sqlRebuild;
	<span style="color: #0000FF;">end</span> catch
<span style="color: #0000FF;">end</span>
go</pre></div></div>

<p>Alternatively, you can adjust the script to <em>REORGANIZE</em> an index when it can&#8217;t rebuild it online.</p>
<p>By the way, if you use <a href="http://ola.hallengren.com/">Ola Hallengren&#8217;s maintenance scripts</a>, he&#8217;s already taken all this logic into account! If you write your own maintenance scripts, feel free to incorporate what I have here.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaeljswart.com/2012/01/rebuild-your-indexes-online-when-you-can/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My favourite search terms</title>
		<link>http://michaeljswart.com/2012/01/my-favourite-search-terms/</link>
		<comments>http://michaeljswart.com/2012/01/my-favourite-search-terms/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 17:00:06 +0000</pubDate>
		<dc:creator>Michael J. Swart</dc:creator>
				<category><![CDATA[Miscelleaneous SQL]]></category>
		<category><![CDATA[Tongue In Cheek]]></category>
		<category><![CDATA[southern oracle expert]]></category>

		<guid isPermaLink="false">http://michaeljswart.com/?p=2419</guid>
		<description><![CDATA[So I recently looked through my web statistics and I wanted to share some of my favourite search terms. These are words or phrases that people have searched for and for good or bad, they've wound up here on my site. Google Analytics helps me browse these search terms and looking through them I learned [...]]]></description>
			<content:encoded><![CDATA[<br />So I recently looked through my web statistics and I wanted to share some of my favourite search terms. These are words or phrases that people have searched for and for good or bad, they've wound up here on my site. Google Analytics helps me browse these search terms and looking through them I learned that
<ul>
	<li><em>Michael</em> is apparently hard to spell</li>
	<li>Some people still include question marks in their search queries. It's quaint. I always assume they're asking "Jeeves"</li>
</ul>
Any way here are my favourites, in no particular order.
<ul>
	<li><strong>dba humour</strong></li>
	<li><strong>trololo</strong></li>
	<li><strong>trololo guy</strong></li>
	<li><strong>monkey throwing darts</strong></li>
	<li><strong>people running from atomic bomb</strong></li>
<em>?</em>
	<li><strong>swart guts</strong></li>
<em>???</em>
	<li><strong>is read uncommitted bad?</strong></li>
<em>Yes</em>
	<li><strong>rid lookup good or bad</strong></li>
<em>Bad</em>
	<li><strong>sql undelete</strong></li>
<em>Nope, sorry about that. <a href="http://weblogs.sqlteam.com/mladenp/archive/2010/10/12/sql-server-ndash-undelete-a-table-and-restore-a-single.aspx">Although</a></em>
	<li><strong>how to forget something</strong></li>
<em>Someone googled that. There's a story there.</em>
	<li><strong>reporting services is fun</strong></li>
<em>you betcha</em>
	<li><strong>10 pockets utility belt</strong></li>
<em>Career in construction or Batman wannabe?</em>
	<li><strong>vampire hierarchy</strong></li>
<em>Sorry, you've come to the wrong place, random googler.</em>
	<li><strong>cartoon cow tossing dog</strong></li>
<em>(strangely enough) You've come to the <a href="http://michaeljswart.com/2011/02/ridiculously-unnormalized-database-schemas-part-three/">right place</a>, random googler.</em>
	<li><strong>how to avoid swart</strong></li>
<em>HAHAHA! If you find out, let me know.</em>
	<li><strong>my software never has bugs. it just develops random features</strong><br />
and<br />
<strong>pivot tables are like good wine you need to learn how to appreciate them</strong></li>
<em>2 things: (1) How did my site come up for these searches and (2) Can we be best friends?</em>
</ul>
By the way, the phrase "You've come to the right place" reminds me of Engywook, the toothless scientist from the movie <em>The Neverending Story</em>. He's an expert on the Southern Oracle (it's his speciality). So I include him here in the hopes that I get at least one ironic google hit for "Oracle expert":<br /><br />

<div id="attachment_2424" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-2424" title="the (Southern) Oracle Expert" src="http://michaeljswart.com/wp-content/uploads/2012/01/Engywook.png" alt="the (Southern) Oracle Expert" width="500" height="300" /><p class="wp-caption-text">the (Southern) Oracle Expert</p></div>]]></content:encoded>
			<wfw:commentRss>http://michaeljswart.com/2012/01/my-favourite-search-terms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Clearing out the closet&#8230;</title>
		<link>http://michaeljswart.com/2012/01/clearing-out-the-closet/</link>
		<comments>http://michaeljswart.com/2012/01/clearing-out-the-closet/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 19:31:15 +0000</pubDate>
		<dc:creator>Michael J. Swart</dc:creator>
				<category><![CDATA[Data Cartoons]]></category>
		<category><![CDATA[Tongue In Cheek]]></category>

		<guid isPermaLink="false">http://michaeljswart.com/?p=2438</guid>
		<description><![CDATA[Hey fellow SQL bloggers, Have you ever written an amazing blog post that just didn&#8217;t pan out because when you reread what you wrote, you found out it was crap? That happens to me sometimes and it&#8217;s frustrating. Here are some illustrations that I&#8217;ve created in the past that just never made the cut. So I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>Hey fellow SQL bloggers,</p>
<p>Have you ever written an amazing blog post that just didn&#8217;t pan out because when you reread what you wrote, you found out it was crap? That happens to me sometimes and it&#8217;s frustrating. Here are some illustrations that I&#8217;ve created in the past that just never made the cut. So I&#8217;ll just leave these here.</p>
<h3>Clean Your Data</h3>
<p><img class="alignnone size-full wp-image-2365" title="A sonic shower apparently." src="http://michaeljswart.com/wp-content/uploads/2011/12/DataAgain.png" alt="" width="500" height="300" /></p>
<h3>SQLHomies</h3>
<p>Just slightly hipper than <a href="http://www.sqlpeople.net/">SQLPeople.net</a></p>
<p><img class="alignnone size-full wp-image-1649" title="sqlhomies" src="http://michaeljswart.com/wp-content/uploads/2011/05/sqlhomies.png" alt="" width="556" height="121" /></p>
<h3>Love Your Data</h3>
<p>Inspired by Karen Lopez&#8217;s favourite quote (Maybe this should have gone before the first picture).</p>
<p><img class="alignnone size-full wp-image-1304" title="Tasha" src="http://michaeljswart.com/wp-content/uploads/2011/02/Tasha.png" alt="" width="500" height="300" /></p>
<h3>Brent Ozar PLF</h3>
<p>I admit it, I&#8217;m a <a href="http://www.brentozar.com/">Brent OPLF</a> fanboy. And once upon a time, Jeremiah Peschka&#8217;s and his beard reminded me of Yukon Cornelius:</p>
<p><img class="alignnone size-full wp-image-2415" title="Had there been five, I would have done a Voltron thing." src="http://michaeljswart.com/wp-content/uploads/2012/01/oplf.png" alt="" width="300" height="300" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://michaeljswart.com/2012/01/clearing-out-the-closet/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Thank you notes&#8230;</title>
		<link>http://michaeljswart.com/2012/01/thank-you-notes/</link>
		<comments>http://michaeljswart.com/2012/01/thank-you-notes/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 17:00:56 +0000</pubDate>
		<dc:creator>Michael J. Swart</dc:creator>
				<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Technical Articles]]></category>

		<guid isPermaLink="false">http://michaeljswart.com/?p=2402</guid>
		<description><![CDATA[Without these tools, this week would have been a lot rougher at work for our team.]]></description>
			<content:encoded><![CDATA[<p>(It&#8217;s been a hectic week. The good news is that I&#8217;ve got loads of topics to write about. The bad news is that I&#8217;ve got no time to do it! Illustrations will make a return next week too because I&#8217;m finally getting that Adobe Illustrator license I&#8217;ve had my eye on. Maybe I&#8217;ll also include a retroactive Jimmy Fallon illustration).</p>
<p>Aaron Bertrand maintains the <a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2010/10/26/useful-free-resources-for-sql-server.aspx">definitive list of free SQL Server tools</a>. I want to give a shout out to just a couple of them. Without these tools, this week would have been a lot rougher at work for our team.</p>
<h3>sp_whoisactive</h3>
<p>Thank you <a href="http://sqlblog.com/blogs/adam_machanic/"><strong>Adam Machanic</strong></a>,<br />
For making a lightweight sproc to help me see at a glance the activity on a SQL Server database. (Also kudos to the parameters @get_plans and @find_block_leaders).</p>
<p>If you&#8217;re unfamiliar with this stored procedure, <a href="http://sqlblog.com/blogs/adam_machanic/archive/2011/04/27/who-is-active-v11-00-a-month-of-activity-monitoring-part-27-of-30.aspx">start here</a>.</p>
<h3>Plan Explorer</h3>
<p>Thank you <a href="http://www.sqlsentry.com"><strong>SQL Sentry</strong></a>,<br />
For making a tool that helps me understand everything about a query plan is doing. (Also kudos to the Expressions tab and the Parameters tab).</p>
<p>Plan Explorer presents SQL Server query plans just a bit nicer than SQL Server Management Studio does. When looking at a problematic query plan, I want to go from looking at a plan to a solution as quick as possible. For me this week, it would be safe to say that Plan Explorer cut that analysis time in half. </p>
<p>If you&#8217;re unfamiliar with this tool, <a href="http://www.sqlsentry.com/plan-explorer/sql-server-query-view.asp">start here</a>.</p>
<h3>Dynamic Management Views</h3>
<p>Thank you <a href="http://www.google.com/search?q=sys.dm_exec_query_stats"><strong>Microsoft (SQL-Server-2005-and-later-DMVs)</strong></a>,<br />
For tracking statistics about query executions and making it possible to examine the history of the db activity without having to trace server activity (so extra kudos to dm_exec_query_stats, dm_exec_cached_plans and dm_exec_query_plan). </p>
<p>I don&#8217;t know whether to call these views free. They&#8217;re available with any database at SQL Server 2005 (or later). So if you&#8217;re using SQL Server, then you can use these DMVs.</p>
<p>If you&#8217;re unfamiliar with these views, <a href="http://www.google.com/search?q=sys.dm_exec_query_stats">start here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaeljswart.com/2012/01/thank-you-notes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Then, Now and Later</title>
		<link>http://michaeljswart.com/2012/01/then-now-and-later/</link>
		<comments>http://michaeljswart.com/2012/01/then-now-and-later/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 17:00:37 +0000</pubDate>
		<dc:creator>Michael J. Swart</dc:creator>
				<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[MVP]]></category>
		<category><![CDATA[resolution]]></category>

		<guid isPermaLink="false">http://michaeljswart.com/?p=2394</guid>
		<description><![CDATA[So happy New Year! This is the week that a lot of people look back on their year and make plans for their new year. Well, I'm no different.]]></description>
			<content:encoded><![CDATA[<p>So happy New Year! This is the week that a lot of people look back on their year and make plans for their new year. Well, I&#8217;m no different. This week I&#8217;m taking a break from the technical content to take a look at 2011 and what 2012 might bring.</p>
<h3>The Past (Looking back at 2011)</h3>
<p>I started blogging a couple years ago. I picked the domain <a href="MichaelJSwart.com">MichaelJSwart.com</a> (with the middle initial) because MichaelSwart.com was taken at the time. I liked the sound of it any way, probably because of Michael J. Fox. My favorite character of his was Marty McFly:</p>
<p><img class="alignnone size-full wp-image-2393" title="Overlook the plot inconsistencies because time travel is too awesome a plot device" src="http://michaeljswart.com/wp-content/uploads/2012/01/MartyMcFly.png" alt="" width="500" height="300" /></p>
<p>And a year ago, (<a href="http://www.midnightdba.com/Jen/2011/01/tsql-tuesday-014/">prompted by Jenn McCown&#8217;s</a> t-sql tuesday post about resolutions) I <a href="http://michaeljswart.com/2011/01/my-2011-resolution/">made a new year&#8217;s resolution</a> to blog weekly, keep the articles technical and to include illustrations.</p>
<p>And I had an absolute blast doing it! So it was easy to keep it up:</p>
<ul>
<li>The topics came from whatever interested me. Luckily I have an interesting job with new and different challenges almost daily.</li>
<li>The time came as by treating the blog as a hobby. I figure the average <a title="Google: time spent watching tv" href="http://michaeljswart.com/wp-admin/www.google.com/search?q=average+time+spent+watching+tv">person has that much free time</a>, it&#8217;s just a matter of how to spend it.</li>
<li>I like to write when I&#8217;m feeling particularly awake.</li>
<li>I like to draw when I&#8217;m not because it&#8217;s more fun and it probably uses a different part of the brain so that it feels like less mental effort.</li>
</ul>
<p>I particpated in a couple SQL Saturdays. The first one in Cleveland was great. Among other things, I learned that if you visit Cleveland&#8217;s art museum at 10 am on  Superbowl Sunday, you have the <em>entire</em> museum to yourself. The second SQL Saturday I attended this year was in my own backyard. I presented for the first time in Toronto and it was exciting.</p>
<h3>The Present (this week)</h3>
<p>So I was excited to learn this week that I received Microsoft&#8217;s <a href="http://mvp.support.microsoft.com/gp/aboutmvp">Most Valuable Professional (MVP) award</a> for SQL Server (achievement unlocked!). I feel honoured to receive the award and inspired to continue writing. I feel like I&#8217;ve learned and benefited from the SQL crowd more than I provided (expertise consumer first, expertise provider second). So many people have helped me but I&#8217;m not going to name names. That&#8217;s next week &#8211; seriously <img src='http://michaeljswart.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  .</p>
<h3>The Future (2012)</h3>
<p>So I&#8217;m going to resolve to continue blogging the way I have for the past year. It&#8217;s a challenging (if not a surprising) resolution. It&#8217;s challenging even though this resolution boils down to <em>resolving to continue a fun hobby</em>. This starts now but I&#8217;m going to hold off on the technical stuff for just one more week: I want to write something about people who inspire me (and why they might inspire you too). Stay tuned.</p>
<p>And also this year, I&#8217;m going to try something new. I want to try to participate in a local user group. Easier said than done because for me, there is no local user group and I&#8217;m going to do something about that. (Ohioans, I love you but the commute is killer <img src='http://michaeljswart.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  )</p>
<p>It&#8217;s all very exciting. Look out 2012, you won&#8217;t know what hit you.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaeljswart.com/2012/01/then-now-and-later/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>A simple message: Merry Christmas</title>
		<link>http://michaeljswart.com/2011/12/a-simple-message-merry-christmas/</link>
		<comments>http://michaeljswart.com/2011/12/a-simple-message-merry-christmas/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 15:00:49 +0000</pubDate>
		<dc:creator>Michael J. Swart</dc:creator>
				<category><![CDATA[Miscelleaneous SQL]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Tongue In Cheek]]></category>

		<guid isPermaLink="false">http://michaeljswart.com/?p=2361</guid>
		<description><![CDATA[From my family to yours, Merry Christmas.]]></description>
			<content:encoded><![CDATA[<p>From my family to yours, Merry Christmas.<br />
<img src="http://michaeljswart.com/wp-content/uploads/2011/12/ChristmasCard2011.png" alt="" title="Have a safe holiday season!" width="504" height="360" class="alignnone size-full wp-image-2362" /></p>
<p>And just to throw in some SQL, here is a query that will return the complete lyrics to Feliz Navidad, (the most repetitive Christmas song in the world):</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>processing<span style="color: #808080;">-</span>instruction<span style="color: #808080;">&#40;</span>complete_lyrics<span style="color: #808080;">&#41;</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">REPLICATE</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">REPLICATE</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">REPLICATE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'
Feliz Navidad, '</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'próspero año y felicidad'</span>, <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">REPLICATE</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">REPLICATE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'
I wanna wish you a Merry Christmas, '</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'from the bottom of my heart'</span>, <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span>,<span style="color: #000;">3</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">for</span> xml <span style="color: #0000FF;">path</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span>,type</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://michaeljswart.com/2011/12/a-simple-message-merry-christmas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Write Better</title>
		<link>http://michaeljswart.com/2011/12/write-better/</link>
		<comments>http://michaeljswart.com/2011/12/write-better/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 04:20:14 +0000</pubDate>
		<dc:creator>Michael J. Swart</dc:creator>
				<category><![CDATA[Miscelleaneous SQL]]></category>
		<category><![CDATA[Writing]]></category>

		<guid isPermaLink="false">http://michaeljswart.com/?p=2371</guid>
		<description><![CDATA[I have a confession to make. I suck at writing. In high school, I was never at the top of my English class]]></description>
			<content:encoded><![CDATA[<p>I have a confession to make. I suck at writing. In high school, I was never at the top of my English class and my University accepted my application despite my English marks. But even though I majored in Math and Computer Science, my essay-writing days weren&#8217;t over. The University I went to required that all students &#8220;<em>demonstrate a proficiency in English</em>&#8221; before graduating. To demonstrate that, we were required to <a href="http://elpp.uwaterloo.ca/elpe.html">write an exam</a>, a single essay. I thought I could get by because English is my first language. So I was surprised when I found out that I failed that exam!  Ugh&#8230;</p>
<p>Then I made a choice which in hindsight turned out to be one of the best things I could have done. In my second year, I signed up for an English course as an elective. It was an introduction to essay writing. I worked hard and did well. In that course I learned a few things I should have learned many years earlier. Those things can be boiled down into:</p>
<ul>
<li>Have something to write</li>
<li>Write it with the reader in mind</li>
<li>Don&#8217;t write anything else</li>
</ul>
<h3>Have something to write</h3>
<p>Or in other words <em>have a point</em>. I&#8217;m going to repeat that because it&#8217;s a lesson I find myself relearning often: <em>Have a point</em>. I need to have something to write more than I need to write something (if that makes sense).</p>
<p>Corollary for bloggers: Don&#8217;t feel guilty about writer&#8217;s block.</p>
<h3>Write it with the reader in mind</h3>
<p>If I&#8217;m writing a blog article, I try to ask myself &#8220;who&#8217;s the reader?&#8221; Some common readers include these people:</p>
<ul>
<li><strong>A keen SQL professional googling for a solution. </strong>I love writing posts for this person. It usually starts with myself googling for a problem and not finding anything (or being disappointed with what I do find). I like to think that I&#8217;m helping people in the same situation I was in. (Examples: <a href="http://michaeljswart.com/2011/02/searching-inside-strings-cpu-is-eight-times-worse-for-unicode-strings/" rel="bookmark">Searching Inside Strings: CPU is Eight Times Worse For Unicode Strings</a>, <a href="http://michaeljswart.com/2008/12/eliminated-null-values/">Eliminated Null Values</a>)</li>
<li><strong>Myself: </strong>I used to write a lot of articles for myself. They were quick scripts that I could quickly get access to as long as I had internet access. I still use them even today (Examples: <a href="http://michaeljswart.com/2009/04/indexing-foreign-keys/">Indexing Foreign Keys</a>, <a href="http://michaeljswart.com/2010/05/disowning-your-relatives/">Disowning Your Relatives</a>)</li>
<li><strong>Potential employers, clients or trainees: </strong>A perfectly valid set of readers, but writing for them is tricky. You&#8217;re bragging (which is okay) but you don&#8217;t want to appear like you&#8217;re bragging (which is not okay) so keep it subtle. Keep the audience in mind. It&#8217;s better if the message is &#8220;I love this stuff&#8221; or &#8220;I can help you&#8221; rather than &#8220;Look how smart I am.&#8221;</li>
<li><strong>RSS Readers and Link Followers: </strong>Yep, that&#8217;s you! (both of you). You enjoy keeping up with SQL Server industry news by following various SQL Server blogs including this one. Something piqued your interest about the title and you started reading (btw, thanks for reading this far!).</li>
</ul>
<h3>Don&#8217;t write anything else</h3>
<p>This is Mark Twain&#8217;s &#8220;<a href="http://google.com/search?q=Fenimore+Cooper's+Literary+Offenses">Employ a simple and straightforward style</a>.&#8221; It&#8217;s also George Orwell&#8217;s &#8220;<a href="https://www.google.com/search?q=Politics+and+the+english+language">If it is possible to cut a word out, always cut it out</a>.&#8221;</p>
<p><img class="alignnone size-full wp-image-2381" title="Who makes me wish for a second that I was American" src="http://michaeljswart.com/wp-content/uploads/2011/12/marktwain.png" alt="" width="500" height="300" /></p>
<p>Writing clearly goes back to having a point. If a sentence, word or paragraph does not help your point then it probably doesn&#8217;t belong. When you omit the unimportant stuff, what&#8217;s left is packed with meaning.</p>
<p>One trick I use is to do a brain dump. I quickly type an outline of what I want to write so that I don&#8217;t forget anything. Often this simple outline gets included into the post verbatim.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://michaeljswart.com/2011/12/write-better/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching using disk: basic
Object Caching 546/546 objects using disk: basic

Served from: michaeljswart.com @ 2012-02-23 04:26:29 -->
