<?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>A Developer&#039;s Blog &#187; Oracle</title>
	<atom:link href="http://blog.hoegaerden.be/tag/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hoegaerden.be</link>
	<description>SQL Server, BI, .NET, IT and anything else I have been playing with.</description>
	<lastBuildDate>Tue, 07 Sep 2010 18:29:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fun With Strings</title>
		<link>http://blog.hoegaerden.be/2009/10/04/fun-with-strings/</link>
		<comments>http://blog.hoegaerden.be/2009/10/04/fun-with-strings/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 11:07:48 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[collation]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2009/10/04/fun-with-strings/</guid>
		<description><![CDATA[Initially I was going to call this article &#8220;Struggling With Collation: The SeQueL&#8221;, but it just doesn&#8217;t have the same ring to it as &#8220;Fun With Strings&#8221;.  In that previous article I showed how you might get different results when loading data from a temporary table or table variable and I suggested that one way [...]]]></description>
			<content:encoded><![CDATA[<p>Initially I was going to call this article &#8220;<a title="Struggling With Collation" href="http://blog.hoegaerden.be/2009/09/20/struggling-with-collation/" target="_blank">Struggling With Collation</a>: The SeQueL&#8221;, but it just doesn&#8217;t have the same ring to it as &#8220;Fun With Strings&#8221;.  In that previous article I showed how you might get different results when loading data from a temporary table or table variable and I suggested that one way of solving this is by switching your data type to nvarchar.</p>
<h2>Unicode Or Not?</h2>
<h3>Reason #1 For Not</h3>
<p>Today I&#8217;m going to show you that nvarchar is not always what we want to use, especially if we don&#8217;t need to support Unicode strings.  Imagine a staging scenario when loading a data warehouse.  Often the Business Keys (BK) are strings, and depending on the source system, sometimes very long strings &#8211; I&#8217;ve seen situations with a combined business key of over 500 bytes!  (You can’t imagine what some data sources look like but that’s another story.)  Do we really want to convert these to Unicode, and thus double their size?  Furthermore, to improve lookups we put indexes on those BKs.  These indexes would double in size as well.  So no, we don&#8217;t really want to make these fields Unicode, and certainly not when we want our ETLs to perform as fast as possible.</p>
<h3>Reason #2 For Not</h3>
<p>That was reason number one why nvarchar is not always the solution.  And here comes reason number two.  In my scenario, the source tables are located in an Oracle database.  And guess what: by default Oracle&#8217;s ORDER BY behaves different than SQL Server&#8217;s ORDER BY (when using the regular Latin1_General_CI_AS or SQL_Latin1_General_CP1_CI_AS collations)!  By default Oracle uses binary string comparison to sort its data and the reason for it appears to be that that&#8217;s the only way to prevent a full table scan.  I&#8217;m no Oracle expert but that&#8217;s <a title="NLS_SORT specifies the collating sequence for ORDER BY queries." href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams130.htm" target="_blank">what the documentation states</a>.</p>
<p>Here’s a little demonstration.  The following script prepares a table variable and selects the data from it, sorted ascending.</p>
<div class="code"><span style="color: #0000ff;">declare</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">table</span><span style="color: #000000;">(</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">varchar</span><span style="color: #000000;">(</span><span style="color: #800000;">20</span><span style="color: #000000;">))</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;AA&#8217;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;A&#8217;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;A-&#8217;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;A A&#8217;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;BA&#8217;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;0&#8242;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;1&#8242;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;-0&#8242;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;-1&#8242;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;A0&#8242;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;0A&#8217;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;-A&#8217;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;-B&#8217;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;a&#8217;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;b&#8217;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">insert</span><span style="color: #808080;"> </span><span style="color: #0000ff;">into</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216; &#8216;</span><span style="color: #0000ff;">;</span><span style="color: #808080;"> </span></p>
<p><span style="color: #808080;"> </span><span style="color: #0000ff;">select</span><span style="color: #808080;"> </span><span style="color: #000000;">*</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">order</span><span style="color: #808080;"> </span><span style="color: #0000ff;">by</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">asc;</span></div>
<p>I have executed it once just as stated above (while connected to a database that uses the SQL_Latin1_General_CP1_CI_AS collation) and once more while using nvarchar as data type for the column in the table variable.  The first execution will sort the data using a non-Unicode sorting algorithm, while the second execution will order the data according to the Unicode sorting method.  The results will be shown further below for easier comparison.</p>
<p>On Oracle I performed a similar procedure, as shown in following script.</p>
<div class="code"><span style="color: #0000ff;">select</span><span style="color: #808080;"> </span><span style="color: #000000;">cast(</span><span style="color: #808080;">&#8216;AA&#8217; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #0000ff;">varchar</span><span style="color: #000000;">(</span><span style="color: #800000;">20</span><span style="color: #000000;">))</span><span style="color: #808080;"> </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;A&#8217; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;A-&#8217; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;A A&#8217; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;BA&#8217; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;0&#8242; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;1&#8242; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;-0&#8242; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;-1&#8242; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;A0&#8242; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;0A&#8217; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;-A&#8217; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;-B&#8217; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;a&#8217; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216;b&#8217; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"> </span><span style="color: #0000ff;">union</span></div>
<div class="code"><span style="color: #0000ff;">select</span><span style="color: #808080;"> &#8216; &#8216; </span><span style="color: #0000ff;">as</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">Dual</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">order</span><span style="color: #808080;"> </span><span style="color: #0000ff;">by</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">asc;</span></div>
<p>The Oracle script doesn’t use a table variable, it just creates a result set using several select statements with a union in between.  But for our test that doesn’t matter, the results using this method are suitable.</p>
<p>In the table below you can see the result of the three executions.</p>
<table style="width: 272pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0" width="362">
<colgroup>
<col style="width: 90pt;" width="120"></col>
<col style="width: 68pt;" width="90"></col>
<col style="width: 67pt;" width="89"></col>
<col style="width: 47pt;" width="63"></col>
</colgroup>
<tbody>
<tr style="height: 15pt;" height="20">
<td class="xl65" style="background: #4f81bd none repeat scroll 0% 0%; width: 90pt; font-family: calibri; height: 15pt; color: white; font-size: 11pt; font-weight: 700; text-decoration: none; border: medium 0.5pt 1.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" width="120" height="20">SQL non-Unicode</td>
<td class="xl65" style="background: #4f81bd none repeat scroll 0% 0%; width: 68pt; font-family: calibri; color: white; font-size: 11pt; font-weight: 700; text-decoration: none; border: medium 0.5pt 1.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" width="90">SQL Unicode</td>
<td class="xl65" style="background: #4f81bd none repeat scroll 0% 0%; width: 67pt; font-family: calibri; color: white; font-size: 11pt; font-weight: 700; text-decoration: none; border: medium 0.5pt 1.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" width="89">Oracle Binary</td>
<td style="background: #4f81bd none repeat scroll 0% 0%; width: 47pt; font-family: calibri; color: white; font-size: 11pt; font-weight: 700; text-decoration: none; border: medium medium 1.5pt none none solid -moz-use-text-color -moz-use-text-color white;" width="63"><span style="mso-spacerun: yes"> </span></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20"><span style="mso-spacerun: yes"> </span></td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none"><span style="mso-spacerun: yes"> </span></td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none"><span style="mso-spacerun: yes"> </span></td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">&lt; space</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">-0</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">0</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">-0</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">-1</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">-0</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">-1</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">-A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">0A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">-A</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">-B</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">1</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">-B</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">0</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">-1</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">0</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">0A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">0A</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">1</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">a</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">1</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">-A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">A</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">a</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">A-</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">A A</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">A A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">A A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">A-</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">A-</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">A0</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">A0</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">A0</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">AA</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">AA</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">AA</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">b</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">BA</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" height="20">b</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">-B</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">a</td>
<td style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: medium none; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none"></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl67" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt medium medium none solid none none -moz-use-text-color white -moz-use-text-color -moz-use-text-color;" height="20">BA</td>
<td class="xl66" style="border-bottom: medium none; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">BA</td>
<td class="xl66" style="border-bottom: medium none; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">b</td>
<td style="font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none"></td>
</tr>
</tbody>
</table>
<p>As you can see, they only agree on one thing: space really is the smallest character in my test set!  And that’s not what I want, I want all the data to be sorted consistently, no matter what the source is.</p>
<h2>But Why Sorted?</h2>
<p>You may wonder why I need to sort the data.  Well, some components in Integration Services expect the incoming data flows to be ordered.  One of the standard components that requires this is the <a title="BOL 2008 - Merge Transformation" href="http://msdn.microsoft.com/en-us/library/ms141703.aspx" target="_blank">Merge Transformation</a>.  Another (custom!) component is <a title="TableDifference - a custom SSIS component" href="http://www.sqlbi.eu/Projects/TableDifference/tabid/74/language/en-US/Default.aspx" target="_blank">Table Difference</a>.  I could of course add a Sort Transformation to my Data Flow, but that would not be interesting for performance.  I want the data to come from the database server in the expected order.  So now I&#8217;ll show you how you can do that.</p>
<h2>Taking Control!</h2>
<h3>SQL Server: ORDER BY … COLLATE …</h3>
<p>On SQL Server this was fairly easy.  The <a title="BOL 2008 - ORDER BY Clause (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms188385.aspx" target="_blank">ORDER BY clause</a> has a COLLATE part where you can specify what collation should be used to order the data.  Because Oracle sorts its data using a binary algorithm, I’ll tell SQL Server to do that as well.  More precisely I’ll tell SQL Server to use the Latin1_General_BIN collation.  The updated SELECT statement from the T-SQL script above looks like this:</p>
<div class="code"><span style="color: #0000ff;">select</span><span style="color: #808080;"> </span><span style="color: #000000;">*</span><span style="color: #808080;"> </span><span style="color: #0000ff;">from</span><span style="color: #808080;"> </span><span style="color: #000000;">@tbl</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">order</span><span style="color: #808080;"> </span><span style="color: #0000ff;">by</span><span style="color: #808080;"> </span><span style="color: #000000;">col1</span><span style="color: #808080;"> </span><span style="color: #0000ff;">collate</span><span style="color: #808080;"> </span><span style="color: #000000;">Latin1_General_BIN</span><span style="color: #808080;"> </span><span style="color: #0000ff;">asc;</span></div>
<h3>Oracle: ORDER BY NLSSORT()</h3>
<p>To ensure that results from Oracle are always returned using the same sorting algorithm, I will also tell the Oracle server to sort it’s data using the binary algorithm.</p>
<p>The first way I came up with was to change the <a title="NLS_SORT" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams130.htm" target="_blank">NLS_SORT</a> setting on the session.  That can be done by executing the following command before the SELECT statement:</p>
<div class="code"><span style="color: #0000ff;">ALTER</span><span style="color: #808080;"> </span><span style="color: #000000;">SESSION</span><span style="color: #808080;"> </span><span style="color: #0000ff;">SET</span><span style="color: #808080;"> </span><span style="color: #000000;">NLS_SORT</span><span style="color: #0000ff;">=BINARY;</span></div>
<p>This method is fine when you’re running the queries manually from a client such as Oracle SQL Developer.  However, in SSIS the OLE DB Source component will not accept anything else besides the SELECT statement.</p>
<p>Then I found another way.  There’s a function called <a title="NLSSORT function" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions099.htm" target="_blank">NLSSORT()</a> which you can apply to a column in the ORDER BY clause.  The following statement demonstrates how to use this function.  (I only show the ORDER BY clause as it can be applied to the Oracle script mentioned earlier.)</p>
<div class="code"><span style="color: #0000ff;">ORDER</span><span style="color: #808080;"> </span><span style="color: #0000ff;">BY</span><span style="color: #808080;"> </span><span style="color: #000000;">NLSSORT(col1,</span><span style="color: #808080;"> &#8216;NLS_SORT=BINARY&#8217;</span><span style="color: #000000;">)</span></div>
<p>The following table shows the results from both binary sort queries:</p>
<table style="width: 135pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0" width="179">
<colgroup>
<col style="width: 68pt;" width="90"></col>
<col style="width: 67pt;" width="89"></col>
</colgroup>
<tbody>
<tr style="height: 15pt;" height="20">
<td class="xl65" style="background: #4f81bd none repeat scroll 0% 0%; width: 68pt; font-family: calibri; height: 15pt; color: white; font-size: 11pt; font-weight: 700; text-decoration: none; border: medium 0.5pt 1.5pt none solid solid -moz-use-text-color white white;" width="90" height="20">SQL Binary</td>
<td class="xl65" style="background: #4f81bd none repeat scroll 0% 0%; width: 67pt; font-family: calibri; color: white; font-size: 11pt; font-weight: 700; text-decoration: none; border: medium 0.5pt 1.5pt medium none solid solid none -moz-use-text-color white white -moz-use-text-color;" width="89">Oracle Binary</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20"><span style="mso-spacerun: yes"> </span></td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none"><span style="mso-spacerun: yes"> </span></td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">-0</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">-0</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">-1</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">-1</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">-A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">-A</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">-B</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">-B</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">0</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">0</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">0A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">0A</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">1</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">1</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">A</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">A A</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">A A</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">A-</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">A-</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">A0</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">A0</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">AA</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">AA</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">BA</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">BA</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #b8cce4 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt 0.5pt none solid solid -moz-use-text-color white white;" height="20">a</td>
<td class="xl66" style="border-bottom: white 0.5pt solid; border-left: medium none; font-family: calibri; background: #b8cce4; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #b8cce4 none">a</td>
</tr>
<tr style="height: 15pt;" height="20">
<td class="xl66" style="background: #dbe5f1 none repeat scroll 0% 0%; font-family: calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; border: medium 0.5pt none solid -moz-use-text-color white;" height="20">b</td>
<td class="xl66" style="border-bottom: medium none; border-left: medium none; font-family: calibri; background: #dbe5f1; color: black; font-size: 11pt; border-top: medium none; font-weight: 400; border-right: white 0.5pt solid; text-decoration: none; text-underline-style: none; text-line-through: none; mso-pattern: #dbe5f1 none">b</td>
</tr>
</tbody>
</table>
<p>Finally I am able to get data from both Oracle and SQL Server using a consistent sort order.</p>
<h3>But, How Big Is NULL?</h3>
<p>However, even on this straightforward request, both database servers do not fully agree!  Here’s what they have to say about the topic:</p>
<p><a title="BOL 2008 - Null Values" href="http://msdn.microsoft.com/en-us/library/ms191504.aspx" target="_blank">“NULL</a> is the smallest.”</p>
<p>“No, it’s the largest.”</p>
<p>“No, smallest!”</p>
<p>“Largest!!”</p>
<p>“Smallest.”</p>
<p>“Largest I tell you!!!”</p>
<p>“Bladiebla, not hearing you, anyway, it’s NOTHING!”</p>
<p>“No, it isn’t!”</p>
<p><em>*discussion goes on and on*</em></p>
<p>If I add NULL to my test data set, SQL Server will sort it first (thus NULL is the smallest value in my test set), while Oracle will put it last.  In my situation it wasn’t really an issue (the BKs are not supposed to be NULL), but it’s quite important to remember in cases where NULLs are actually possible.</p>
<h2>Conclusion</h2>
<p>When working with strings, always keep collation in mind.  And even more so when dealing with several different source systems!</p>
<p><strong>Additional reference material:</strong></p>
<p><a title="The Globalization of Language in Oracle - The NLS_COMP and NLS_SORT variables" href="http://www.databasejournal.com/features/oracle/article.php/3488751/The-Globalization-of-Language-in-Oracle---The-NLSCOMP-and-NLSSORT-variables.htm" target="_blank">Database Journal: The Globalization of Language in Oracle &#8211; The NLS_COMP and NLS_SORT variables</a></p>
<p><a title="How to: Sort Data for the Merge and Merge Join Transformations" href="http://msdn.microsoft.com/en-us/library/ms137653.aspx" target="_blank">BOL 2008: How to: Sort Data for the Merge and Merge Join Transformations</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2009/10/04/fun-with-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSIS: Loading a datetime from Oracle</title>
		<link>http://blog.hoegaerden.be/2009/08/27/ssis-loading-a-datetime-from-oracle/</link>
		<comments>http://blog.hoegaerden.be/2009/08/27/ssis-loading-a-datetime-from-oracle/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 19:33:25 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2009/08/27/ssis-loading-a-datetime-from-oracle/</guid>
		<description><![CDATA[Imagine an Integration Services package where you need to load data from an Oracle database.  Typical for ETL you try to use a timestamp field in the source table to determine if there were any changes since last load.  Let’s say that field is called LAST_MODIFICATION.  The query that you’re using to load the data [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine an Integration Services package where you need to load data from an Oracle database.  Typical for ETL you try to use a timestamp field in the source table to determine if there were any changes since last load.  Let’s say that field is called LAST_MODIFICATION.  The query that you’re using to load the data is parameterized and the value passed in is the highest timestamp of the previous Load (or should I say Extract?).  So your query may look something like this:</p>
<div class="code"><span style="color: #0000ff;">SELECT</span><span style="color: #808080;"> </span><span style="color: #000000;">*</span><span style="color: #808080;"> </span><span style="color: #0000ff;">FROM</span><span style="color: #808080;"> </span><span style="color: #000000;">THE_SCHEMA.THE_TABLE</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">WHERE</span><span style="color: #808080;"> </span><span style="color: #000000;">LAST_MODIFICATION</span><span style="color: #808080;"> </span><span style="color: #000000;">&gt;</span><span style="color: #808080;"> </span><span style="color: #000000;">to_date(?,</span><span style="color: #808080;"> &#8216;yyyy/mm/dd hh:mi:ss&#8217;</span><span style="color: #000000;">)</span></div>
<div></div>
<p>In this query the question mark gets replaced with a datetime value, for instance ‘2009/08/27 21:26:32’.  (Yeah, I know, you shouldn’t select star but that’s not the point of this post.)</p>
<p>When running your package you suddenly get the following error:</p>
<blockquote><p>ORA-01849: hour must be between 1 and 12</p></blockquote>
<p>After some cursing and trial and error, you decide to have a closer look at <a title="Oracle TO_DATE() DATE_FORMAT" href="http://download.oracle.com/docs/cd/B28359_01/olap.111/b28126/dml_commands_1029.htm#BABEFHFG" target="_blank">Oracle’s to_date() function</a>.  And there is your answer: HH returns the same as HH12, an hour between 1 and 12.  Which is not what we want here, we want hours starting at 1 and ending at 23.  So we should use HH24 instead.  A correct query would be:</p>
<p><span style="color: #0000ff;">SELECT</span><span style="color: #808080;"> </span><span style="color: #000000;">*</span><span style="color: #808080;"> </span><span style="color: #0000ff;">FROM</span><span style="color: #808080;"> </span><span style="color: #000000;">THE_SCHEMA.THE_TABLE</span><span style="color: #808080;"><br />
</span><span style="color: #0000ff;">WHERE</span><span style="color: #808080;"> </span><span style="color: #000000;">LAST_MODIFICATION</span><span style="color: #808080;"> </span><span style="color: #000000;">&gt;</span><span style="color: #808080;"> </span><span style="color: #000000;">to_date(?,</span><span style="color: #808080;"> &#8216;yyyy/mm/dd hh24:mi:ss&#8217;</span><span style="color: #000000;">)</span></p>
<p>Another lesson learned… (and noted in case I need it again <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> )</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2009/08/27/ssis-loading-a-datetime-from-oracle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
