<?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; SSIS</title>
	<atom:link href="http://blog.hoegaerden.be/tag/ssis/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>Sun, 11 Jul 2010 12:19:25 +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>Remove Unused Columns From The Data Flow</title>
		<link>http://blog.hoegaerden.be/2010/05/12/remove-unused-columns-from-the-data-flow/</link>
		<comments>http://blog.hoegaerden.be/2010/05/12/remove-unused-columns-from-the-data-flow/#comments</comments>
		<pubDate>Wed, 12 May 2010 16:25:47 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Integration Services 2008]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/05/12/remove-unused-columns-from-the-data-flow/</guid>
		<description><![CDATA[Consider the following scenario. You&#8217;ve been developing some SSIS packages, nicely making sure that all errors and warnings are gone from the Error List window. So the next step is to deploy the packages to the server and schedule them. After some days you decide to have a look at the sysssislog table and discover [...]]]></description>
			<content:encoded><![CDATA[<p>Consider the following scenario. You&#8217;ve been developing some SSIS packages, nicely making sure that all errors and warnings are gone from the Error List window. So the next step is to deploy the packages to the server and schedule them. After some days you decide to have a look at the <a title="BOL 2008: sysssislog (Transact-SQL)" href="http://technet.microsoft.com/en-us/library/ms186984.aspx" target="_blank">sysssislog</a> table and discover that it&#8217;s filled with OnWarning records!</p>
<p>Well, this is an extreme example of course. Careful developers would notice the warnings in either the Output window or the Progress tab while testing the package in the BIDS.</p>
<p>All these warnings are indicating that some columns in your data flows have become obsolete.  Here&#8217;s an example:</p>
<blockquote><p>The output column &#8220;BKCustomerID&#8221; (13529) on output &#8220;OLE DB Source Output&#8221; (12088) and component &#8220;OLE_SRC MySource&#8221; (12077) is not subsequently used in the Data Flow task. Removing this unused output column can increase Data Flow task performance.</p></blockquote>
<p>The problem with these warnings is not only that they slow down the transformation process but they obfuscate the SSIS log with thousands of records, making it difficult for you when you need to investigate an issue. And this is something that you really don’t want, especially when the business people are calling you to ask why the data is not up-to-date on the production servers.</p>
<p>If you ever wished that you&#8217;d see these warnings whilst developing the package instead of at runtime only, now&#8217;s your chance to make a change. Or better, to ask Microsoft to implement the change.</p>
<p><a title="Connect: Dataflow unused columns should be highlighed in BIDS" href="https://connect.microsoft.com/SQLServer/feedback/details/553088/dataflow-unused-columns" target="_blank"><strong>Follow this link to cast your vote on Connect!</strong></a></p>
<p>Thank you Jamie <a title="SSIS code smell – Unused columns in the dataflow" href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/04/21/ssis-code-smell-unused-columns-in-the-dataflow.aspx" target="_blank">for pointing this out</a>.</p>
<p>Have fun!</p>
<p>Valentino.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2010/05/12/remove-unused-columns-from-the-data-flow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importing Data Using The Wizard: Mixing The Wrong Ingredients</title>
		<link>http://blog.hoegaerden.be/2010/05/03/importing-data-using-the-wizard-mixing-the-wrong-ingredients/</link>
		<comments>http://blog.hoegaerden.be/2010/05/03/importing-data-using-the-wizard-mixing-the-wrong-ingredients/#comments</comments>
		<pubDate>Mon, 03 May 2010 20:39:18 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/05/03/importing-data-using-the-wizard-mixing-the-wrong-ingredients/</guid>
		<description><![CDATA[A while ago I wrote an article about how you can use the SQL Server Import and Export wizard to import Excel data into a SQL Server database.  In this sequel I’m going to show you some problems which you may encounter when using that wizard.  Just like any good old wizard, he’s only as [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote an <a title="Importing Excel Data Using Integration Services" href="http://blog.hoegaerden.be/2010/04/20/importing-excel-data-using-integration-services/">article about how you can use the SQL Server Import and Export wizard to import Excel data into a SQL Server database</a>.  In this sequel I’m going to show you some problems which you may encounter when using that wizard.  Just like any good old wizard, he’s only as good as his recipes.  If a recipe is missing an ingredient, the resulting potion will probably not behave as expected and before you know it it explodes in your face.</p>
<p>I’ll be using the same Excel file as in my previous article.  In case you’re having some problems understanding the data or locating certain screens mentioned in this article, I recommend you to first <a title="Importing Excel Data Using Integration Services" href="http://blog.hoegaerden.be/2010/04/20/importing-excel-data-using-integration-services/">read the prequel</a>.</p>
<h2>Some Common Wizard Pitfalls And Their Solution</h2>
<h3>Drop And Re-Create Destination Table</h3>
<p>Imagine that for your import process you’re planning to import that Excel data regularly.  So the logical step is to make sure that each time the process runs, it starts from scratch.  Following that, what seems to be an interesting checkbox is located on the <strong>Column Mappings</strong> screen.  This checkbox is called<em> Drop and re-create destination table</em>.</p>
<p><img style="display: inline; border: 0px;" title="Column Mappings: Drop and re-create destination table" src="http://blog.hoegaerden.be/wp-content/uploads/image234.png" border="0" alt="Column Mappings: Drop and re-create destination table" width="608" height="486" /></p>
<p>So you activate that checkbox and execute the package.  However, it ends with an error in the Executing phase:</p>
<p><img style="display: inline; border: 0px;" title="SQL Server Import and Export Wizard: error while Executing" src="http://blog.hoegaerden.be/wp-content/uploads/image235.png" border="0" alt="SQL Server Import and Export Wizard: error while Executing" width="566" height="579" /></p>
<p>Here’s what the error details say:</p>
<p><img style="display: inline; border: 0px;" title="image" src="http://blog.hoegaerden.be/wp-content/uploads/image236.png" border="0" alt="image" width="621" height="167" /></p>
<blockquote><p>Error 0xc002f210: Drop table failed… Cannot drop the table dbo.ProductList$ because it does not exist or you do not have permission.</p></blockquote>
<p>So why does this error occur?  Let’s examine the SSIS package that was generated.  This is what the Control Flow looks like:</p>
<p><img style="display: inline; border: 0px;" title="A Control Flow that doesn't take a non-existing table into account" src="http://blog.hoegaerden.be/wp-content/uploads/image237.png" border="0" alt="A Control Flow that doesn't take a non-existing table into account" width="161" height="232" /></p>
<p>New here is that Drop table SQL Task.  Taking a closer look at the task, here’s the query:</p>
<pre class="code"><span style="color: blue;">drop table </span>[dbo]<span style="color: gray;">.</span>[ProductList$]
<span style="color: blue;">GO</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>So the first task is to drop the table.  This flow does not take into account that the table may not yet exist, as is the case here, causing the error.</p>
<p>However, do you notice the blue arrow connecting the Drop table task with the next SQL Task?  That means that it doesn’t require the execution of the task to end successfully, the flow will continue even when an error occurred (unlike when the green connector – meaning Success – is used).</p>
<p>Double-clicking the blue connector gives us the <strong>Precedence Constraint Editor</strong> window:</p>
<p><img style="display: inline; border: 0px;" title="Precedence Constraint Editor" src="http://blog.hoegaerden.be/wp-content/uploads/image238.png" border="0" alt="Precedence Constraint Editor" width="645" height="483" /></p>
<p>Indeed, the value for the constraint is set to <em>Completion</em>.</p>
<p>This also explains why the wizard continued executing all phases, even though an error occurred.  And the end result was that the table is really created, containing the data as expected.</p>
<p>If you’d like to avoid the error and handle the non-existing table, you could replace the query in the Drop table SQL Task with the following one:</p>
<pre class="code"><span style="color: blue;">if </span><span style="color: gray;">exists
(
    </span><span style="color: blue;">select </span><span style="color: gray;">* </span><span style="color: blue;">from </span><span style="color: green;">INFORMATION_SCHEMA</span><span style="color: gray;">.</span><span style="color: green;">TABLES </span>T
    <span style="color: blue;">where </span>T<span style="color: gray;">.</span>TABLE_NAME <span style="color: gray;">= </span><span style="color: red;">'ProductList$'
        </span><span style="color: gray;">and </span>T<span style="color: gray;">.</span>TABLE_SCHEMA <span style="color: gray;">= </span><span style="color: red;">'dbo'
</span><span style="color: gray;">)
    </span><span style="color: blue;">drop table </span>[dbo]<span style="color: gray;">.</span>[ProductList$]<span style="color: gray;">;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>It first checks if the table exists, taking schema into account, and will only perform the DROP TABLE statement if the table actually exists.</p>
<h3>Field Length Insufficient</h3>
<p>On to the next possible issue.  When examining our Excel sheet we find out that the content of the Class column is either blank or just one character:</p>
<p><img style="display: inline; border: 0px;" title="Possible values of the Class field" src="http://blog.hoegaerden.be/wp-content/uploads/image239.png" border="0" alt="Possible values of the Class field" width="287" height="308" /></p>
<p>So we decide to change its type to char(1), again using the <strong>Column Mappings</strong> screen.</p>
<p><img style="display: inline; border: 0px;" title="Column Mappings: change type to char(1)" src="http://blog.hoegaerden.be/wp-content/uploads/image240.png" border="0" alt="Column Mappings: change type to char(1)" width="584" height="653" /></p>
<p>However, clicking Finish at the end of the wizard gives us a fatal error:</p>
<p><img style="display: inline; border: 0px;" title="SQL Server Import and Export Wizard: Operatoin stopped in Error" src="http://blog.hoegaerden.be/wp-content/uploads/image241.png" border="0" alt="SQL Server Import and Export Wizard: Operatoin stopped in Error" width="566" height="579" /></p>
<p>And these are the details of the error:</p>
<ul>
<li>
<ul>
<li>Error 0xc02020c5: Data Flow Task 1: Data conversion failed while converting column &#8220;Class&#8221; (63) to column &#8220;Class&#8221; (139).  The conversion returned status value 4 and status text<strong> &#8220;Text was truncated or one or more characters had no match in the target code page.&#8221;</strong>.(SQL Server Import and Export Wizard)</li>
<li>Error 0xc020902a: Data Flow Task 1: The &#8220;output column &#8220;Class&#8221; (139)&#8221; failed because truncation occurred, and the truncation row disposition on &#8220;output column &#8220;Class&#8221; (139)&#8221; specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
<p>(SQL Server Import and Export Wizard)</li>
<li>Error 0xc0047022: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component &#8220;Data Conversion 0 &#8211; 0&#8243; (131) failed with error code 0xC020902A while processing input &#8220;Data Conversion Input&#8221; (132). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.
<p>(SQL Server Import and Export Wizard)</li>
</ul>
</li>
</ul>
<p>Wow, that’s quite a long list for such a simple change!  Apparently it wasn’t such a good idea to limit the length of this field.  But why does this error occur?  After all, the values in this field are just one character long.  Except, after taking a closer look at the Excel sheet it turns out that these values contain a trailing space!</p>
<p>One way of avoiding this issue is by specifying a higher length for the field.  In this particular case however, you may decide to modify your <strong>Data Flow</strong> so that it removes the trailing space.  Here’s what the Data Flow currently looks like:</p>
<p><img style="display: inline; border: 0px;" title="Data Flow to import Excel data" src="http://blog.hoegaerden.be/wp-content/uploads/image242.png" border="0" alt="Data Flow to import Excel data" width="147" height="221" /></p>
<p>The <strong>Data Conversion transformation</strong> takes care of converting the Class column into a DT_STR of length 1.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image243.png"><img style="display: inline; border: 0px;" title="Data Conversion Transformation Editor" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb57.png" border="0" alt="Data Conversion Transformation Editor" width="684" height="593" /></a></p>
<p>We’re going to replace that <strong>Data Conversion Transformation</strong> with another one, a <strong>Derived Column transformation</strong>.  This is one of the transformations which I’m using all the time.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image244.png"><img style="display: inline; border: 0px;" title="Derived Column Transformation Editor" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb58.png" border="0" alt="Derived Column Transformation Editor" width="682" height="545" /></a></p>
<p>As you can see in the screenshot, I’ve set it up so that it uses <a title="BOL 2008: TRIM (SSIS Expressions)" href="http://msdn.microsoft.com/en-us/library/ms139947.aspx" target="_blank">the TRIM() function</a> on the Class input column to remove any leading or trailing spaces.  Furthermore I’m using a cast to DT_STR of length 1 to ensure the correct field type.  The resulting column is called Class_STR, to clearly indicate that it has been converted to DT_STR.</p>
<p>This is the resulting Data Flow:</p>
<p><img style="display: inline; border: 0px;" title="Data Flow: Destination component complains about lineage ID" src="http://blog.hoegaerden.be/wp-content/uploads/image245.png" border="0" alt="Data Flow: Destination component complains about lineage ID" width="178" height="234" /></p>
<p>Looks like we’ve got an issue with our Destination component now.  Which is quite logical: we still need to tell it that it should use the newly-created Class_STR column.  So double-click the component.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image246.png"><img style="display: inline; border: 0px;" title=" Restore Invalid Column References Editor" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb59.png" border="0" alt=" Restore Invalid Column References Editor" width="694" height="507" /></a></p>
<p>Double-clicking the Destination component will open up the<strong> Restore Invalid Column References Editor</strong>.  In Available Columns, select the new Class_STR column to replace the Class column which was used previously.</p>
<p>That’s it, your SSIS package will now remove the trailing spaces from the Class column and store it in a column of char(1).</p>
<h3>Excel Layout Change</h3>
<p>Here’s another common issue when dealing with Excel SSIS imports.  If you’re not 100% in control of that Excel sheet, someone will someday make a structural change to it and it will cause your import process to fail.</p>
<p>In this really simple example I’ve opened up the Excel sheet and renamed the Color column to Colour.  Which is something that may happen in real life: a British person takes over the maintenance of that product list and sees that the Color column is spelled the wrong way, and corrects it without informing anyone.</p>
<p>What does that mean for our import?  Here’s the result when manually executing the package using <a title="BOL 2008: How to: Run a Package Using the DTExecUI Utility" href="http://msdn.microsoft.com/en-us/library/ms141707.aspx" target="_blank">DTExecUI.exe</a>:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image247.png"><img style="display: inline; border: 0px;" title="DTExecUI: Package Execution Progress" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb60.png" border="0" alt="DTExecUI: Package Execution Progress" width="688" height="313" /></a></p>
<p>In this case execution will fail because the package cannot find the Color column in the Excel sheet.  More precisely it says VS_NEEDSNEWMETADATA.  This is a really common error when using Integration Services, but you need to manually update the package to handle such changes.</p>
<p>In other words: try to be in control of that sheet as much as you can, and if possible: set up another way to maintain such data.  For instance by using a <a title="SQL Server 2008 R2 Master Data Services" href="http://www.microsoft.com/sqlserver/2008/en/us/mds.aspx" target="_blank">Master Data Management system</a>.  But that’s stuff for later on, in future articles.</p>
<h2>Conclusion</h2>
<p>As long as you’re aware of some of the common issues into which you may run, I still think the Import and Export Wizard is an interesting option to start your first SSIS package.  When running into an issue, I recommend to open up the SSIS package and have a closer look through the Business Intelligence Development Studio.  Then make any changes there so you can handle the errors.</p>
<p>Happy importing!</p>
<p>Valentino.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2010/05/03/importing-data-using-the-wizard-mixing-the-wrong-ingredients/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Importing Excel Data Using Integration Services</title>
		<link>http://blog.hoegaerden.be/2010/04/20/importing-excel-data-using-integration-services/</link>
		<comments>http://blog.hoegaerden.be/2010/04/20/importing-excel-data-using-integration-services/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 21:21:02 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/04/20/importing-excel-data-using-integration-services/</guid>
		<description><![CDATA[In a previous article I’ve shown you how to import data from an Excel sheet using the OPENROWSET() function.&#160; And I concluded by stating that it’s not the best option when automating your data import.
Today I’ll repeat the Excel data import process by using SQL Server Integration Services, also known as SSIS.
I’ll be using SQL [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous article I’ve shown you <a title="Retrieving Data From Excel" href="http://blog.hoegaerden.be/2010/03/29/retrieving-data-from-excel/" target="_blank">how to import data from an Excel sheet using the OPENROWSET() function</a>.&#160; And I concluded by stating that it’s not the best option when automating your data import.</p>
<p>Today I’ll repeat the Excel data import process by using SQL Server Integration Services, also known as SSIS.</p>
<p>I’ll be using SQL Server 2008 R2, but I’m quite sure that the process is very similar to the first release of 2008, and even to 2005.&#160; The Excel file that I will be importing is the one used in my previous article, and I’ll also refer to some parts of that article, so you may want to have a read over that one when something here isn’t clear.</p>
<p>Furthermore I’m using a Windows 7 64-bit machine, with <a title="2010 Office System Driver Beta: Data Connectivity Components" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=C06B8369-60DD-4B64-A44B-84B371EDE16D&amp;amp;displaylang=ja&amp;displaylang=en" target="_blank">the ACE 14 driver</a> (beta) installed.&#160; To avoid any discussion about versions and for my own (future) reference, here’s the result of a SELECT @@VERSION:</p>
<blockquote><p>Microsoft SQL Server 2008 R2 (CTP) &#8211; 10.50.1352.12 (X64)&#160;&#160; Oct 30 2009 18:06:48&#160;&#160; Copyright (c) Microsoft Corporation&#160; Enterprise Evaluation Edition (64-bit) on Windows NT 6.1 &lt;X64&gt; (Build 7600: ) </p>
</blockquote>
<h2>Create SSIS Package To Import Excel Data</h2>
<p>Usually you will start by creating a new package in an Integration Services project, add an Excel source to a new Data Flow, throw in some Data Flow Transformations and end your flow with an OLE DB Destination connecting to your SQL Server.</p>
<p>But that’s not the approach that I’ll take in this article.&#160; I’ll make use of a shortcut (and meanwhile I’m showing you how well integrated some components really are).</p>
<p>First, I’m creating a new database called <em>ExcelImport</em>, using the Management Studio (aka SSMS).&#160; Once the database is created, right-click on it and choose Tasks &gt; Import Data.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Start the Import Data Wizard through Management Studio" border="0" alt="Start the Import Data Wizard through Management Studio" src="http://blog.hoegaerden.be/wp-content/uploads/image213.png" width="586" height="652" /> </p>
<p>This will open up the <a title="BOL 2008: Importing and Exporting Data by Using the SQL Server Import and Export Wizard" href="http://msdn.microsoft.com/en-us/library/ms141209.aspx" target="_blank">SQL Server Import And Export Data Wizard</a>.&#160; Like all good wizards, it starts with a <strong>Welcome</strong> screen containing an introductory text about its purpose – something about “create simple packages that import and export data between many popular data formats including databases, spreadsheets” – and so on.&#160; It also includes a checkbox that says “Do not show this starting page again”.&#160; That’s my favorite object on the page <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> &#160; Okay, I agree, the page is useful for people who have never seen the wizard before and who may have opened it up by accident, but that’s about as far as its use goes methinks.</p>
<p>So, do whatever you like with the checkbox and click Next.&#160; That opens up the <strong>Choose a Data Source</strong> screen.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SQL Server Import and Export Wizard - Choose a Data Source" border="0" alt="SQL Server Import and Export Wizard - Choose a Data Source" src="http://blog.hoegaerden.be/wp-content/uploads/image214.png" width="566" height="579" /> </p>
<p>In that screen you have several options in the Data Source dropdown.&#160; The one we’re interested in is called <em>Microsoft Excel</em>.&#160; Once that option is selected, the controls further down the screen change into what is shown in the screenshot.&#160; Select your file and the right version, in my case I’ve got an Excel 2007 file.&#160; If your sheet contains a header row, activate the <em>First row has column names</em> checkbox.</p>
<p>Clicking Next will open up the <strong>Choose a Destination</strong> screen.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SQL Server Import and Export Wizard - Choose a Destination" border="0" alt="SQL Server Import and Export Wizard - Choose a Destination" src="http://blog.hoegaerden.be/wp-content/uploads/image215.png" width="566" height="579" /> </p>
<p>In that screen, select <em>Microsoft OLE DB Provider for SQL Server</em> as Destination.&#160; Ensure that your SQL Server instance is the right one in the <em>Server Name</em> dropdown and the <em>Authentication</em> is filled out as expected.&#160; The correct database should be selected by default because we did a right-click on it to start the wizard.</p>
<p>Another Next click opens up the <strong>Specify Table Copy or Query</strong> window.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SQL Server Import and Export Wizard - Specify Table Copy or Query" border="0" alt="SQL Server Import and Export Wizard - Specify Table Copy or Query" src="http://blog.hoegaerden.be/wp-content/uploads/image216.png" width="566" height="579" /> </p>
<p>Here we can choose between either retrieving the full table – all rows, all columns – or writing a query ourselves.&#160; I’ll go for the first option.</p>
<p>Click Next once more to open the <strong>Select</strong> <strong>Source Tables and Views</strong> screen.&#160; That name seems a bit weird in the context of an Excel import but I guess that’s not really important here.&#160; Just read it as “Select the sheet that you’d like to import”.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SQL Server Import and Export Wizard - Select Source Table and Views" border="0" alt="SQL Server Import and Export Wizard - Select Source Table and Views" src="http://blog.hoegaerden.be/wp-content/uploads/image217.png" width="567" height="579" />&#160;</p>
<p>I’ll go for the ProductList$ Source.&#160; The sheet in my Excel file is called ProductList.&#160; Note that the Destination is editable – I’m changing the destination table to dbo.ProductList (with the dollar sign removed).</p>
<p>If you’d like to view your data right now you can hit the Preview button.&#160; It opens up a window such as this one:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SQL Server Import and Export Wizard - Select Source Table and Views - Preview Data" border="0" alt="SQL Server Import and Export Wizard - Select Source Table and Views - Preview Data" src="http://blog.hoegaerden.be/wp-content/uploads/image218.png" width="528" height="338" />&#160; </p>
<p>That should look familiar.</p>
<p>A more interesting button is the one called <em>Edit Mappings</em>.&#160; Clicking that button opens a screen that lets you change the destination table’s schema.&#160; By default, all columns that seem to be numeric are mapped to a type of float and all the others are mapped to nvarchar with a length of 255.&#160; Depending on your situation you can either leave it as it is (in case you’re just loading a staging table and want to handle data conversions later on) or you should review each column (for instance when you’re erasing and loading the full table every night and this is the actual table being used by other processes).</p>
<p><strong>Note:</strong> whenever a column contains a blank cell, its type will be nvarchar(255), even when all other values are numeric.&#160; Also, if you don’t need Unicode support, don’t use nvarchar but change it to varchar instead.</p>
<p>Here’s the <strong>Column Mappings </strong>screen with some of the defaults changed:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="The Column Mappings window" border="0" alt="The Column Mappings window" src="http://blog.hoegaerden.be/wp-content/uploads/image219.png" width="636" height="794" /> </p>
<p>Everything that I changed has been indicated using the yellow marker.&#160; I’ve changed some field types and lenghts, made one field non-nullable and adapted the destination name.</p>
<p>Clicking OK followed by Next brings us to the following screen, <strong>Review Data Type Mapping</strong>.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image220.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SQL Server Import and Export Wizard - Review Data Type Mapping" border="0" alt="SQL Server Import and Export Wizard - Review Data Type Mapping" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb56.png" width="678" height="834" /></a> </p>
<p>This screen gives another overview of all the columns that we’re planning to import.&#160; Note that each column of which we’ve changed the type has gotten a nice yellow warning sign.&#160; This happens because a data conversion needs to occur, and there’s always something that can go wrong when converting data.&#160; The<em> On Error</em> and <em>On Truncation</em> columns show the action that should happen when such an event occurs.&#160; We’ll leave them all at <em>Use Global</em>.&#160; The Global settings are located at the bottom of the screen and are both set to <em>Fail</em>.&#160; That’s the best option at the moment (the only other one is <em>Ignore</em> but that means you won’t get any notification in case of an error or truncation problem).</p>
<p>After clicking Next we end up at the <strong>Save and Run Package</strong> window.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SQL Server Import and Export Wizard - Save and Run Package" border="0" alt="SQL Server Import and Export Wizard - Save and Run Package" src="http://blog.hoegaerden.be/wp-content/uploads/image221.png" width="644" height="579" /> </p>
<p>I have activated the <em>Save SSIS Package</em> checkbox and chose the <em>Do not save sensitive data</em> option.&#160; By default it is saved in SQL Server, which is actually the MSDB.&#160; That’s good because we’re going to examine the contents of the package later on so we want to keep it.</p>
<p>The <em>Run immediately </em>checkbox was activated by default.&#160; This will execute the package in the last step of the wizard.</p>
<p>Another Next click and we’re on the <strong>Save SSIS Package </strong>screen.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SQL Server Import and Export Wizard - Save SSIS Package" border="0" alt="SQL Server Import and Export Wizard - Save SSIS Package" src="http://blog.hoegaerden.be/wp-content/uploads/image222.png" width="566" height="579" /> </p>
<p>Here we can give our package a decent name, such as ExcelImport.&#160; You can also see the server on which I’m saving the package.</p>
<p>The final Next click brings us to the <strong>Complete the Wizard</strong> screen, woohoo!</p>
<p>&#160;<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SQL Server Import and Export Wizard - Complete the Wizard" border="0" alt="SQL Server Import and Export Wizard - Complete the Wizard" src="http://blog.hoegaerden.be/wp-content/uploads/image223.png" width="566" height="579" /> </p>
<p>We can see a short overview of what we’ve configured in the previous steps.&#160; Click Finish to execute and save the package!</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SQL Server Import and Export Wizard - The execution was successful" border="0" alt="SQL Server Import and Export Wizard - The execution was successful" src="http://blog.hoegaerden.be/wp-content/uploads/image224.png" width="566" height="579" /> </p>
<p>And we’ve successfully executed the package!</p>
<h2>Taking A Closer Look At The SSIS Package</h2>
<p>When connecting to the Integration Services server (through SSMS for instance), I now have a new package in the root of the MSDB folder.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="The ExcelImport SSIS package, stored in MSDB" border="0" alt="The ExcelImport SSIS package, stored in MSDB" src="http://blog.hoegaerden.be/wp-content/uploads/image225.png" width="269" height="171" /> </p>
<p>It’s located there because I chose to save the package to SQL Server.</p>
<h3>Adding An Existing Package To An SSIS Project</h3>
<p>We’re now going to open it in the Business Intelligence Development Studio (aka BIDS).&#160; So, open the BIDS and create a new SSIS Project (or use an existing one, doesn’t really matter).</p>
<p>Once the project is open, right-click the SSIS Packages folder in the Solution Explorer and select <em>Add Existing Package</em>.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Right-click SSIS Packages folder in Solution Explorer to Add Existing Package" border="0" alt="Right-click SSIS Packages folder in Solution Explorer to Add Existing Package" src="http://blog.hoegaerden.be/wp-content/uploads/image226.png" width="357" height="316" /> </p>
<p>That opens up the <em>Add Copy of Existing Package</em> window.</p>
<p><strong>Sidenote</strong>: do you see that <em>SSIS Import and Export Wizard</em> option in the previous screenshot?&#160; That’s right, the wizard that we’ve used extensively in the earlier part of this article can be launched from here as well.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Add Copy of Existing Package" border="0" alt="Add Copy of Existing Package" src="http://blog.hoegaerden.be/wp-content/uploads/image227.png" width="600" height="438" /> </p>
<p>Select <em>SSIS Package Store</em> as location of the package and enter the name of your server in the second dropdown.&#160; Once that is done you can click the button with the ellipsis and select your package under the MSDB node.</p>
<p>Clicking OK will add the package to your project in the Solution Explorer.&#160; Double-click it to open it up.</p>
<h3>The Control Flow</h3>
<p>In the Control Flow you can see two components: a SQL Task that contains a CREATE TABLE statement and a Data Flow.</p>
<p>Here’s what the CREATE TABLE statement looks like:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CREATE TABLE statement in the Execute SQL Task" border="0" alt="CREATE TABLE statement in the Execute SQL Task" src="http://blog.hoegaerden.be/wp-content/uploads/image228.png" width="336" height="479" /> </p>
<p>As you can see, the table is created using the column names and types just like we configured them through the wizard.</p>
<p>Important to note here is that the Control Flow does not take anything else into account.&#160; For instance, what happens if we execute the package twice?&#160; It will fail because the table already exists!</p>
<p>In case you don’t believe me, just try it out!</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Execute SQL Statement failed" border="0" alt="Execute SQL Statement failed" src="http://blog.hoegaerden.be/wp-content/uploads/image229.png" width="167" height="149" />&#160;<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="There is already an object named &#39;ProductList&#39; in the database." border="0" alt="There is already an object named &#39;ProductList&#39; in the database." src="http://blog.hoegaerden.be/wp-content/uploads/image230.png" width="861" height="144" />&#160;</p>
<h3>The Data Flow</h3>
<p>Opening up the Data Flow we see that it contains three components: an Excel source component that uses an Excel Connection Manager to connect to our now well-known Excel sheet, a Data Conversion Transformation to take care of the conversions that we requested and an OLE DB Destination that uses an OLE DB Connection Manager to connect to our SQL Server.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="The Data Flow to transfer Excel data into SQL Server" border="0" alt="The Data Flow to transfer Excel data into SQL Server" src="http://blog.hoegaerden.be/wp-content/uploads/image232.png" width="165" height="227" /> </p>
<p>Important to note here is that whenever an issue occurs, such as a conversion problem, the flow will fail.</p>
<p>In production environments, certain events need to be taken into account.&#160; The purpose of this article was just to show you how you can use a wizard to generate an SSIS package for you.&#160; You can now use this package as the basis for a well-developed Excel Import template.</p>
<h2>Conclusion</h2>
<p>With this article I hope to have shown you how to use Integration Services to import Excel data, and also that the Management Studio knows how to use other SQL Server components, such as SSIS, quite well.</p>
<p>If you’re running into some issues while using the wizard, or you just like reading what I write, <a title="Importing Data Using The Wizard: Mixing The Wrong Ingredients" href="http://blog.hoegaerden.be/2010/05/03/importing-data-using-the-wizard-mixing-the-wrong-ingredients/">check out my follow-up article covering some common pitfalls</a>.</p>
<p>Need to go to sleep now, long drive tomorrow, PASS European Conference in Germany!&#160; I do hope that Adam Saxton will be there because I was planning to see his presentations all day long.&#160; I already read that one of the speakers – Brent Ozar – won’t be able to make it.&#160; Darned ash cloud…&#160; Next time someone starts talking to me about Azure I’ll run away screaming.</p>
<p>Just kidding <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="Microsoft Support: How to import data from Excel to SQL Server" href="http://support.microsoft.com/kb/321686" target="_blank">Microsoft Support: How to import data from Excel to SQL Server</a></p>
</p>
<p><a title="BOL 2008 - How to: Run the SQL Server Import and Export Wizard" href="http://msdn.microsoft.com/en-us/library/ms140052.aspx" target="_blank">How to: Run the SQL Server Import and Export Wizard</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2010/04/20/importing-excel-data-using-integration-services/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Recursively Delete SSIS Folder</title>
		<link>http://blog.hoegaerden.be/2010/02/28/recursively-delete-ssis-folder/</link>
		<comments>http://blog.hoegaerden.be/2010/02/28/recursively-delete-ssis-folder/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 21:12:51 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/02/28/recursively-delete-ssis-folder/</guid>
		<description><![CDATA[A while ago I posted a query to create a list of all the Integration Services packages deployed to the MSDB.  I am now using that query to take it a step further.
If you’ve been using SSIS for a while you’ve probably noticed that the Management Studio doesn’t like to delete Integration Services folders that [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I posted <a title="List All SSIS Packages Deployed On Your Integration Server" href="http://blog.hoegaerden.be/2010/01/10/list-all-ssis-packages-deployed-on-your-integration-server/" target="_blank">a query to create a list of all the Integration Services packages deployed to the MSDB</a>.  I am now using that query to take it a step further.</p>
<p>If you’ve been using SSIS for a while you’ve probably noticed that the Management Studio doesn’t like to delete Integration Services folders that are not empty.  In fact, it will politely ask you if you’re sure that you want to delete the folder on which you’ve just selected the “Delete” option through the right-click menu.</p>
<p><img style="display: inline; border: 0px;" title="Right-click pop-up menu on SSIS folder" src="http://blog.hoegaerden.be/wp-content/uploads/image195.png" border="0" alt="Right-click pop-up menu on SSIS folder" width="393" height="160" /></p>
<p><img style="display: inline; border: 0px;" title="I am sure I want to delete this non-empty SSIS folder" src="http://blog.hoegaerden.be/wp-content/uploads/image196.png" border="0" alt="I am sure I want to delete this non-empty SSIS folder" width="621" height="137" /></p>
<p>So you click the Yes button.  But then it shows you the following message:</p>
<blockquote><p>SSIS folder &#8216;FolderWithSubfolders&#8217; contains packages and/or other folders. You must drop these first. (Microsoft SQL Server Native Client 10.0)</p></blockquote>
<p>Graphically it looks like this:</p>
<p><img style="display: inline; border: 0px;" title="Object Explorer pop-up: you can't delete SSIS folders that contain packages or other folders" src="http://blog.hoegaerden.be/wp-content/uploads/image197.png" border="0" alt="Object Explorer pop-up: you can't delete SSIS folders that contain packages or other folders" width="621" height="137" /></p>
<p>And this message can be really annoying if you’ve got a main folder with, let’s say, five subfolders, and each subfolder contains about 20-30 packages.  If you want to delete this folder you first need to delete each package separately and then delete the five subfolders, and then you can finally delete the main folder.  And all that through the right-click pop-up menu because you can’t just select the object in the Object Explorer and hit the Delete button on the keyboard – it doesn’t have an action on SSIS objects…</p>
<p>So, I wasn’t planning on doing such a job manually and came up with the following stored procedure.</p>
<p>It’s probably a bit long but don’t run away just yet, I will explain what’s going on down below the code, and there are some comments in the code as well.</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<pre class="code"><span style="color: green;">/*
DESCRIPTION: Deletes all folders and packages under, and including, specified folder.
WRITTEN BY:  Valentino Vranken
CREATED:     2010-02-28
VERSION:     1.0
USAGE:
  -- mind the forward slash
  EXEC dbo.SSIS_RecursiveDeleteFolder '/FolderWithSubfolders'
  -- to delete a subfolder
  EXEC dbo.SSIS_RecursiveDeleteFolder '/FolderWithSubfolders/ASubfolderWithPackages'

COPIED FROM: http://blog.hoegaerden.be

Note 1: folder names are not case-sensitive
Note 2: uses system tables and (undocumented) stored procedures located in MSDB.
Note 3: this code was written for SQL Server 2008. For 2005:
  o sysssispackagefolders -&gt; sysdtspackagefolders90
  o sysssispackages -&gt; sysdtspackages90
  o sp_ssis_deletefolder -&gt; sp_dts_deletefolder
  o sp_ssis_deletepackage -&gt; sp_dts_deletepackage
*/
</span><span style="color: blue;">CREATE PROCEDURE </span>dbo<span style="color: gray;">.</span>SSIS_RecursiveDeleteFolder
    @Folder <span style="color: blue;">varchar</span><span style="color: gray;">(</span>2000<span style="color: gray;">)
</span><span style="color: blue;">AS
BEGIN
    set nocount on</span><span style="color: gray;">;

    </span><span style="color: blue;">declare </span>@foldersToDelete <span style="color: blue;">table
    </span><span style="color: gray;">(
        </span>folderid <span style="color: blue;">uniqueidentifier</span><span style="color: gray;">,
        </span>Lvl <span style="color: blue;">int
    </span><span style="color: gray;">);

    </span><span style="color: blue;">declare </span>@packagesToDelete <span style="color: blue;">table
    </span><span style="color: gray;">(
        </span>PackageName <span style="color: blue;">sysname</span><span style="color: gray;">,
        </span>folderid <span style="color: blue;">uniqueidentifier</span><span style="color: gray;">,
        </span>Lvl <span style="color: blue;">int
    </span><span style="color: gray;">);

    </span><span style="color: green;">--retrieve list of folders to be deleted
    </span><span style="color: blue;">with </span>ChildFolders
    <span style="color: blue;">as
    </span><span style="color: gray;">(
        </span><span style="color: blue;">select </span>PARENT<span style="color: gray;">.</span>parentfolderid<span style="color: gray;">, </span>PARENT<span style="color: gray;">.</span>folderid<span style="color: gray;">, </span>PARENT<span style="color: gray;">.</span>foldername<span style="color: gray;">,
            </span><span style="color: magenta;">cast</span><span style="color: gray;">(</span><span style="color: red;">'' </span><span style="color: blue;">as sysname</span><span style="color: gray;">) </span><span style="color: blue;">as </span>RootFolder<span style="color: gray;">,
            </span><span style="color: magenta;">cast</span><span style="color: gray;">(</span>PARENT<span style="color: gray;">.</span>foldername <span style="color: blue;">as varchar</span><span style="color: gray;">(</span><span style="color: magenta;">max</span><span style="color: gray;">)) </span><span style="color: blue;">as </span>FullPath<span style="color: gray;">,
            </span>0 <span style="color: blue;">as </span>Lvl
        <span style="color: blue;">from </span>msdb<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span>sysssispackagefolders PARENT
        <span style="color: blue;">where </span>PARENT<span style="color: gray;">.</span>parentfolderid <span style="color: gray;">is null
        </span><span style="color: blue;">UNION </span><span style="color: gray;">ALL
        </span><span style="color: blue;">select </span>CHILD<span style="color: gray;">.</span>parentfolderid<span style="color: gray;">, </span>CHILD<span style="color: gray;">.</span>folderid<span style="color: gray;">, </span>CHILD<span style="color: gray;">.</span>foldername<span style="color: gray;">,
            </span><span style="color: blue;">case </span>ChildFolders<span style="color: gray;">.</span>Lvl
                <span style="color: blue;">when </span>0 <span style="color: blue;">then </span>CHILD<span style="color: gray;">.</span>foldername
                <span style="color: blue;">else </span>ChildFolders<span style="color: gray;">.</span>RootFolder
            <span style="color: blue;">end as </span>RootFolder<span style="color: gray;">,
            </span><span style="color: magenta;">cast</span><span style="color: gray;">(</span>ChildFolders<span style="color: gray;">.</span>FullPath <span style="color: gray;">+ </span><span style="color: red;">'/' </span><span style="color: gray;">+ </span>CHILD<span style="color: gray;">.</span>foldername <span style="color: blue;">as varchar</span><span style="color: gray;">(</span><span style="color: magenta;">max</span><span style="color: gray;">))
                </span><span style="color: blue;">as </span>FullPath<span style="color: gray;">,
            </span>ChildFolders<span style="color: gray;">.</span>Lvl <span style="color: gray;">+ </span>1 <span style="color: blue;">as </span>Lvl
        <span style="color: blue;">from </span>msdb<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span>sysssispackagefolders CHILD
            <span style="color: gray;">inner join </span>ChildFolders <span style="color: blue;">on </span>ChildFolders<span style="color: gray;">.</span>folderid <span style="color: gray;">= </span>CHILD<span style="color: gray;">.</span>parentfolderid
    <span style="color: gray;">)
    </span><span style="color: blue;">insert into </span>@foldersToDelete
    <span style="color: blue;">select </span>F<span style="color: gray;">.</span>folderid<span style="color: gray;">, </span>F<span style="color: gray;">.</span>Lvl
    <span style="color: blue;">from </span>ChildFolders F
    <span style="color: blue;">where </span>F<span style="color: gray;">.</span>FullPath <span style="color: gray;">like </span>@Folder <span style="color: gray;">+ </span><span style="color: red;">'%'</span><span style="color: gray;">;

    </span><span style="color: green;">--retrieve list of packages to be deleted
    </span><span style="color: blue;">with </span>ChildFolders
    <span style="color: blue;">as
    </span><span style="color: gray;">(
        </span><span style="color: blue;">select </span>PARENT<span style="color: gray;">.</span>parentfolderid<span style="color: gray;">, </span>PARENT<span style="color: gray;">.</span>folderid<span style="color: gray;">, </span>PARENT<span style="color: gray;">.</span>foldername<span style="color: gray;">,
            </span><span style="color: magenta;">cast</span><span style="color: gray;">(</span><span style="color: red;">'' </span><span style="color: blue;">as sysname</span><span style="color: gray;">) </span><span style="color: blue;">as </span>RootFolder<span style="color: gray;">,
            </span><span style="color: magenta;">cast</span><span style="color: gray;">(</span>PARENT<span style="color: gray;">.</span>foldername <span style="color: blue;">as varchar</span><span style="color: gray;">(</span><span style="color: magenta;">max</span><span style="color: gray;">)) </span><span style="color: blue;">as </span>FullPath<span style="color: gray;">,
            </span>0 <span style="color: blue;">as </span>Lvl
        <span style="color: blue;">from </span>msdb<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span>sysssispackagefolders PARENT
        <span style="color: blue;">where </span>PARENT<span style="color: gray;">.</span>parentfolderid <span style="color: gray;">is null
        </span><span style="color: blue;">UNION </span><span style="color: gray;">ALL
        </span><span style="color: blue;">select </span>CHILD<span style="color: gray;">.</span>parentfolderid<span style="color: gray;">, </span>CHILD<span style="color: gray;">.</span>folderid<span style="color: gray;">, </span>CHILD<span style="color: gray;">.</span>foldername<span style="color: gray;">,
            </span><span style="color: blue;">case </span>ChildFolders<span style="color: gray;">.</span>Lvl
                <span style="color: blue;">when </span>0 <span style="color: blue;">then </span>CHILD<span style="color: gray;">.</span>foldername
                <span style="color: blue;">else </span>ChildFolders<span style="color: gray;">.</span>RootFolder
            <span style="color: blue;">end as </span>RootFolder<span style="color: gray;">,
            </span><span style="color: magenta;">cast</span><span style="color: gray;">(</span>ChildFolders<span style="color: gray;">.</span>FullPath <span style="color: gray;">+ </span><span style="color: red;">'/' </span><span style="color: gray;">+ </span>CHILD<span style="color: gray;">.</span>foldername <span style="color: blue;">as varchar</span><span style="color: gray;">(</span><span style="color: magenta;">max</span><span style="color: gray;">))
                </span><span style="color: blue;">as </span>FullPath<span style="color: gray;">,
            </span>ChildFolders<span style="color: gray;">.</span>Lvl <span style="color: gray;">+ </span>1 <span style="color: blue;">as </span>Lvl
        <span style="color: blue;">from </span>msdb<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span>sysssispackagefolders CHILD
            <span style="color: gray;">inner join </span>ChildFolders <span style="color: blue;">on </span>ChildFolders<span style="color: gray;">.</span>folderid <span style="color: gray;">= </span>CHILD<span style="color: gray;">.</span>parentfolderid
    <span style="color: gray;">)
    </span><span style="color: blue;">insert into </span>@packagesToDelete
    <span style="color: blue;">select </span>P<span style="color: gray;">.</span>name<span style="color: gray;">, </span>F<span style="color: gray;">.</span>folderid<span style="color: gray;">, </span>F<span style="color: gray;">.</span>Lvl
    <span style="color: blue;">from </span>ChildFolders F
        <span style="color: gray;">inner join </span>msdb<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span>sysssispackages P <span style="color: blue;">on </span>P<span style="color: gray;">.</span>folderid <span style="color: gray;">= </span>F<span style="color: gray;">.</span>folderid
    <span style="color: blue;">where </span>F<span style="color: gray;">.</span>FullPath <span style="color: gray;">like </span>@Folder <span style="color: gray;">+ </span><span style="color: red;">'%'</span><span style="color: gray;">;

    </span><span style="color: green;">--use cursor to loop over objects to be deleted
    </span><span style="color: blue;">declare </span>objectsToDelete_cursor <span style="color: blue;">cursor
    for
        select </span>P<span style="color: gray;">.</span>folderid<span style="color: gray;">, </span>P<span style="color: gray;">.</span>Lvl<span style="color: gray;">, </span>P<span style="color: gray;">.</span>PackageName<span style="color: gray;">, </span><span style="color: red;">'P' </span><span style="color: blue;">as </span>ObjectType
        <span style="color: blue;">from </span>@packagesToDelete P
        <span style="color: blue;">UNION </span><span style="color: gray;">ALL
        </span><span style="color: blue;">select </span>F<span style="color: gray;">.</span>folderid<span style="color: gray;">, </span>F<span style="color: gray;">.</span>Lvl<span style="color: gray;">, null, </span><span style="color: red;">'F'
        </span><span style="color: blue;">from </span>@foldersToDelete F
        <span style="color: blue;">order by </span>Lvl <span style="color: blue;">desc</span><span style="color: gray;">, </span>ObjectType <span style="color: blue;">desc</span><span style="color: gray;">;

    </span><span style="color: blue;">open </span>objectsToDelete_cursor<span style="color: gray;">;

    </span><span style="color: blue;">declare </span>@folderid <span style="color: blue;">uniqueidentifier</span><span style="color: gray;">;
    </span><span style="color: blue;">declare </span>@lvl <span style="color: blue;">int</span><span style="color: gray;">;
    </span><span style="color: blue;">declare </span>@packageName <span style="color: blue;">sysname</span><span style="color: gray;">;
    </span><span style="color: blue;">declare </span>@objectType <span style="color: blue;">char</span><span style="color: gray;">;

    </span><span style="color: blue;">fetch next from </span>objectsToDelete_cursor
    <span style="color: blue;">into </span>@folderid<span style="color: gray;">, </span>@lvl<span style="color: gray;">, </span>@packageName<span style="color: gray;">, </span>@objectType<span style="color: gray;">;

    </span><span style="color: blue;">while </span><span style="color: magenta;">@@FETCH_STATUS </span><span style="color: gray;">= </span>0
    <span style="color: blue;">begin
        if </span>@objectType <span style="color: gray;">= </span><span style="color: red;">'F'
        </span><span style="color: blue;">begin
            print </span><span style="color: red;">'exec msdb.dbo.sp_ssis_deletefolder '
                </span><span style="color: gray;">+ </span><span style="color: magenta;">cast</span><span style="color: gray;">(</span>@folderid <span style="color: blue;">as varchar</span><span style="color: gray;">(</span><span style="color: magenta;">max</span><span style="color: gray;">));
            </span><span style="color: blue;">exec </span>msdb<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span><span style="color: maroon;">sp_ssis_deletefolder </span>@folderid<span style="color: gray;">;
        </span><span style="color: blue;">end
        else
        begin
            print </span><span style="color: red;">'exec msdb.dbo.sp_ssis_deletepackage '
                </span><span style="color: gray;">+ </span>@packageName <span style="color: gray;">+ </span><span style="color: red;">', ' </span><span style="color: gray;">+ </span><span style="color: magenta;">cast</span><span style="color: gray;">(</span>@folderid <span style="color: blue;">as varchar</span><span style="color: gray;">(</span><span style="color: magenta;">max</span><span style="color: gray;">));
            </span><span style="color: blue;">exec </span>msdb<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span><span style="color: maroon;">sp_ssis_deletepackage </span>@packageName<span style="color: gray;">, </span>@folderid<span style="color: gray;">;
        </span><span style="color: blue;">end

        fetch next from </span>objectsToDelete_cursor
        <span style="color: blue;">into </span>@folderid<span style="color: gray;">, </span>@lvl<span style="color: gray;">, </span>@packageName<span style="color: gray;">, </span>@objectType<span style="color: gray;">;
    </span><span style="color: blue;">end</span><span style="color: gray;">;

    </span><span style="color: blue;">close </span>objectsToDelete_cursor<span style="color: gray;">;
    </span><span style="color: blue;">deallocate </span>objectsToDelete_cursor<span style="color: gray;">;
</span><span style="color: blue;">END</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Before trying to dismantle this stored procedure, I recommend you to read <a title="List All SSIS Packages Deployed On Your Integration Server" href="http://blog.hoegaerden.be/2010/01/10/list-all-ssis-packages-deployed-on-your-integration-server/" target="_blank">my previous article on retrieving the list of packages</a>.  That already explains half of the code, if not 75%.</p>
<p>Our mission is to find a way to recursively delete packages and folders contained in a specified folder.  To be able to loop over those objects in the correct order (from the deepest level up until the level of the folder specified), the SP creates two table variables: one to hold all folders under the specified folder (@foldersToDelete) and one to hold the packages under the specified folder, including all subfolders (@packagesToDelete).</p>
<p>Based on those two lists I create a cursor that joins these two together, taking their level and object type into consideration.  That’s important because we first need to delete the packages in the lowest level folder, followed by their containing folder, then move one level up and do the same.</p>
<p>We then use the cursor to loop over the packages and folders and use two undocumented system stored procedures – one for each object type- to delete the package or folder.  These system SPs are located in the MSDB.  Here’s how they are defined:</p>
<pre class="code"><span style="color: blue;">ALTER PROCEDURE </span>[dbo]<span style="color: gray;">.</span>[sp_ssis_deletefolder]
  @folderid <span style="color: blue;">uniqueidentifier
AS</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<pre class="code"><span style="color: blue;">ALTER PROCEDURE </span>[dbo]<span style="color: gray;">.</span>[sp_ssis_deletepackage]
  @name <span style="color: blue;">sysname</span><span style="color: gray;">,
  </span>@folderid <span style="color: blue;">uniqueidentifier
AS</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>As you can see, the parameters for these procedures are not that complicated.  Both of them expect a <em>uniqueidentifier</em> as identification for the folder.  That’s okay, these IDs are stored in the <em>msdb.dbo.sysssispackagefolders</em> table and retrieved by our queries to create the list of to-be-deleted objects.</p>
<p>Furthermore, the <em>sp_ssis_deletepackage</em> SP expects the name of the package to be deleted.  Not a problem either, those names are obtained from the<em> msdb.dbo.sysssispackages</em> table.</p>
<p><strong>Note for SQL Server 2005 users:</strong> this code was written for SQL Server 2008.  The system stored procedures and system tables exist in 2005 as well, but they have different names.  See the comment header of my SP for more details.</p>
<p>So, let’s give it a little test.  Following screenshot shows the setup.  What I will do is use the stored procedure to delete the <em>FolderWithSubfolders</em> folder.  If you’ve been paying close attention, that is the same folder which I tried to delete manually through the Management Studio’s right-click menu (see first screenshot above).</p>
<p><img style="display: inline; border: 0px;" title="Overview of my deployed folders and packages" src="http://blog.hoegaerden.be/wp-content/uploads/image198.png" border="0" alt="Overview of my deployed folders and packages" width="255" height="207" /></p>
<p>After creating the SP, I ran following command:</p>
<pre class="code"><span style="color: blue;">EXEC </span>dbo<span style="color: gray;">.</span>SSIS_RecursiveDeleteFolder <span style="color: red;">'/FolderWithSubfolders'</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>And that gave me the following output in the Messages pane:</p>
<blockquote><p>exec msdb.dbo.sp_ssis_deletepackage AnotherPackage, 7F38288D-4370-40A8-80E3-E92283033E4C</p>
<p>exec msdb.dbo.sp_ssis_deletepackage Package, 7F38288D-4370-40A8-80E3-E92283033E4C</p>
<p>exec msdb.dbo.sp_ssis_deletefolder 4102ED59-ED75-4D93-BBAE-0A162447BF02</p>
<p>exec msdb.dbo.sp_ssis_deletefolder 7F38288D-4370-40A8-80E3-E92283033E4C</p>
<p>exec msdb.dbo.sp_ssis_deletefolder C156B436-8C78-4BF9-99F9-5ABFAB10C405</p></blockquote>
<p>I have deliberately put a couple of print commands in the stored procedure to dump the commands that are actually being executed.  This gives us a good idea of what’s going on.</p>
<p>That’s it for now folks.  Thank you for reading this, and if you found it useful or you’ve got some questions about it: post a comment!</p>
<p>Have fun!</p>
<p>Valentino.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2010/02/28/recursively-delete-ssis-folder/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SSIS: Adding Files To The Miscellaneous Folder</title>
		<link>http://blog.hoegaerden.be/2010/02/11/ssis-adding-files-to-the-miscellaneous-folder/</link>
		<comments>http://blog.hoegaerden.be/2010/02/11/ssis-adding-files-to-the-miscellaneous-folder/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 22:20:14 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[TFS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/02/11/ssis-adding-files-to-the-miscellaneous-folder/</guid>
		<description><![CDATA[Sometimes my posts are over 20 pages long when pasted into a Word document.&#160; That&#8217;s when I call them article, or tutorial.&#160; Other times I post real quickies about little things that have annoyed me in the past, because I had to spend too much time looking for a solution to a certain issue, or [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes my posts are over 20 pages long when pasted into a Word document.&#160; That&#8217;s when I call them article, or tutorial.&#160; Other times I post real quickies about little things that have annoyed me in the past, because I had to spend too much time looking for a solution to a certain issue, or just because they are not very obvious and I can image fellow developers doing a search on the internet on that specific subject.</p>
<p>This post is one of the latter.</p>
<p>In a <strong>SQL Server Integration Services project</strong>, have you ever wondered how on earth you can get files into that <strong>Miscellaneous folder</strong>?&#160; When you right-click on the folder in the Solution Explorer, nothing happens, no pop-up menu.</p>
<p>Well, the answer is simple, once you know it.</p>
<p>All you need to do is go one level up in the tree and right-click the Project node in the Solution Explorer.&#160; In the menu that appears, select Add &gt; Existing Item&#8230;.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="How to add a file to the SSIS Miscellaneous folder" border="0" alt="How to add a file to the SSIS Miscellaneous folder" src="http://blog.hoegaerden.be/wp-content/uploads/image176.png" width="352" height="397" /> </p>
<p>In the pop-up window, navigate to any file that you&#8217;d like to add to the project.&#160; Files of a different type than the usual SSIS files such as .dtsx and .ds are automatically added under the Miscellaneous folder.&#160; When adding files, they will be automatically copied to the SSIS project folder, no matter where they were stored originally.&#160; See, not that complicated&#8230; once you know it!</p>
<p>In the following screenshot I’ve added three different file types to the folder, just to prove that it’s working.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Miscellaneous folder with some files added to it" border="0" alt="Miscellaneous folder with some files added to it" src="http://blog.hoegaerden.be/wp-content/uploads/image177.png" width="279" height="241" /> </p>
<p>I like using this folder to store files that belong with that particular project.&#160; Examples of those are configuration files, XSLT files for complex XML conversions, and also the SQL scripts that create my databases.&#160; Each time when I make schema changes, I update the scripts.&#160; And as I&#8217;m using TFS integration, I can rest assured that I always have a backup of my files.&#160; (At least, assuming the TFS team is doing their job &#8211; this is usually beyond my responsibility <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> )</p>
<p>Speaking about <a title="Team Foundation Server Home" href="http://msdn.microsoft.com/en-us/teamsystem/dd408382.aspx" target="_blank">TFS</a>, watch out if you use Business Intelligence Development Studio 2008 to connect to Team Foundation Server 2005!&#160; There&#8217;s an interesting setting in the Options screen (through the Tools menu), located in the<strong> Source Control</strong> &gt; <strong>Visual Studio Team Foundation Server</strong> page.&#160; This setting is called <strong><em>Get latest version of file on check out</em></strong>.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image178.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Get latest version of item on check out" border="0" alt="Get latest version of item on check out" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb50.png" width="674" height="392" /></a> </p>
<p>However, there&#8217;s one caveat!&#160; On TFS2005 it doesn&#8217;t do anything!&#160; If you&#8217;re not aware of that, you may get an annoying surprise when you&#8217;re trying to check in your changes because you may have been working on an outdated version of your package!&#160; And as you probably already know: merging two versions of an SSIS package is, well, what shall I call it, a challenge?</p>
<p>Another setting that helps you to avoid the issue described above is located under<strong> Source Control</strong> &gt; <strong>Environment</strong> and is called <strong><em>Get everything when a solution or project is opened</em></strong>.&#160; Activate this setting and each time when you open your project, you&#8217;ll get a popup window which allows you to Get the latest version of the files.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image179.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Get evrything when a solution or project is opened" border="0" alt="Get evrything when a solution or project is opened" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb51.png" width="677" height="394" /></a> </p>
<p>That leaves one more possible conflict situation.&#160; If someone changes a package on the same day as you, the second person will need to explicitly do a Get Latest Version or he/she will be working on an outdated version.&#160; So, communicate with your team mates so that you know if someone has gotten an assignment that collides with yours.&#160; Of course, this last problem is just a theoretical possibility.&#160; In teams, work is usually divided so that developers do not need to work with more than one person on the same piece of code.&#160; The same logic applies to SSIS packages.</p>
</p>
</p>
<p>And remember, have fun!</p>
<p>Valentino.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2010/02/11/ssis-adding-files-to-the-miscellaneous-folder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SSIS And Its Data Types</title>
		<link>http://blog.hoegaerden.be/2010/01/22/ssis-and-its-data-types/</link>
		<comments>http://blog.hoegaerden.be/2010/01/22/ssis-and-its-data-types/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 19:48:29 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/01/22/ssis-and-its-data-types/</guid>
		<description><![CDATA[If you&#8217;ve got some experience building Data Flows in your Integration Services packages, you probably already know that SSIS has its own representation of the different data types.  The names of these data types start with DT_, followed by the actual type such as BOOL for boolean and STR for string.
Some data types you use [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve got some experience building Data Flows in your Integration Services packages, you probably already know that SSIS has its own representation of the different data types.  The names of these data types start with DT_, followed by the actual type such as BOOL for boolean and STR for string.</p>
<p>Some data types you use every day and others only once in a while.  So some you already know by heart and others you don&#8217;t.  A nice example of one that I certainly don&#8217;t need to look up anymore is the following cast as used in a <a title="BOL 2008: Derived Column Transformation" href="http://msdn.microsoft.com/en-us/library/ms141069.aspx">Derived Column Transformation</a>: (DT_STR, 100, 1252)YourField.  It converts YourField to a string field of length 100 using the ANSI &#8211; Latin 1 code page.</p>
<p>But the reason for this post are the other types, the ones not used daily.  Because each time that I need info on one of those, I find myself ploughing through several BOL pages before finding that page of which I know it exists but where, oh where?!</p>
<p>So, on the following Books Online page you can find a <strong>list of all SSIS data types and their definition</strong>: <a title="BOL 2008: Integration Services Data Types" href="http://msdn.microsoft.com/en-us/library/ms141036.aspx">Integration Services Data Types</a></p>
<p>And at the bottom of that same page there&#8217;s an interesting table showing the <strong>mapping between the SSIS types and those of several RDBMS</strong>, including SQL Server of course.</p>
<p>Another interesting page is this one: <a title="BOL 2008: Working with Data Types in the Data Flow" href="http://msdn.microsoft.com/en-us/library/ms345165.aspx">Working with Data Types in the Data Flow</a></p>
<p>The bottom half of this page contains a <strong>mapping table between the SSIS data types and their corresponding managed type in .NET</strong>.  This is especially useful when you&#8217;re doing some custom development like a <a title="BOL 2008: Developing a Custom Data Flow Component" href="http://msdn.microsoft.com/en-us/library/ms136078.aspx">custom data flow component</a>.  But you don&#8217;t need to take it that far, even when you&#8217;re just using the built-in <a title="BOL 2008: Script Component" href="http://msdn.microsoft.com/en-us/library/ms137640.aspx">Script Component</a> task for some complex data conversions, you&#8217;ll find this useful.  After all, you&#8217;re also programming in a managed .NET language in that component.</p>
<p>Okay, that&#8217;s it for now, hopefully this will save you some time searching for those reference pages.  I already know that I&#8217;ll be coming back to this post once in a while <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/2010/01/22/ssis-and-its-data-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>List All SSIS Packages Deployed On Your Integration Server</title>
		<link>http://blog.hoegaerden.be/2010/01/10/list-all-ssis-packages-deployed-on-your-integration-server/</link>
		<comments>http://blog.hoegaerden.be/2010/01/10/list-all-ssis-packages-deployed-on-your-integration-server/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 21:23:40 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[ETL]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/01/10/list-all-ssis-packages-deployed-on-your-integration-server/</guid>
		<description><![CDATA[When deploying packages to SQL Server Integration Services, it&#8217;s advisable to set up a folder structure so that you can easily distinguish packages belonging to different projects.&#160; Furthermore it may be interesting to create subfolders under the main project folder to separate packages according to the different phases in your ETL (Extract, Transform, Load) process.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>When deploying packages to SQL Server Integration Services, it&#8217;s advisable to set up a folder structure so that you can easily distinguish packages belonging to different projects.&#160; Furthermore it may be interesting to create subfolders under the main project folder to separate packages according to the different phases in your <a title="Wikipedia: Extract, transform, load" href="http://en.wikipedia.org/wiki/Extract,_transform,_load" target="_blank">ETL (Extract, Transform, Load)</a> process.&#160; When loading a data warehouse, interesting folder names are Dimensions for your dimension ETLs and Facts for the packages that load the fact tables.</p>
<p>After a while you end up with lots of packages spread over lots of folders.&#160; To get a good view of what is deployed on your server, it may be interesting to find a way to list all the packages.&#160; And that&#8217;s exactly the reason why I&#8217;m writing this article.</p>
<p>The query further down generates <strong>a list of all packages deployed in the MSDB database</strong> on your SQL Server.&#160; What you get is the name of the packages, their location and version-related information.&#160; I&#8217;ve also created a&#160; RootFolder column so that it&#8217;s easy to filter on project.&#160; (See now why it&#8217;s interesting to create separate folders per project?)</p>
<p>It’s <strong>important to note</strong> that packages deployed to the <strong>File System will not be shown</strong> in the list.&#160; After all, they are not stored in the MSDB database but in a folder somewhere on the server&#8217;s hard drive, more precisely in a subfolder of where you&#8217;ve installed your SQL Server.&#160; In case you&#8217;ve forgotten where that was, here&#8217;s a small tip.&#160; On your server, open up the list of Windows Services (Start &gt; Run &gt; type &quot;services.msc&quot; &gt; enter) and locate the service called <em>SQL Server Integration Services 10.0</em>.&#160; Open the properties of that service and have a look at the <em>Path to executable</em> value in the General tab.&#160; Take the path, drop the \Binn part and add \Packages instead.&#160; That is where, by default, the packages are deployed.&#160; (If you’re running SQL Server 2005, apply the same procedure but look for a service called <em>SQL Server Integration Services</em>.)</p>
<p>On my system, this is where the packages are located: D:\Program Files\Microsoft SQL Server\100\DTS\Packages.&#160; I will also prove it with following screenshot:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Packages deployed to the file system on SSIS 2008" border="0" alt="Packages deployed to the file system on SSIS 2008" src="http://blog.hoegaerden.be/wp-content/uploads/image140.png" width="381" height="82" /></p>
<p>Okay, time for the real stuff, the query:</p>
<pre class="code"><span style="color: green">/*
    DESCRIPTION: Lists all SSIS packages deployed to the MSDB database.
    WRITTEN BY: Valentino Vranken
    VERSION: 1.1
    COPIED FROM: http://blog.hoegaerden.be

    Note: this query was written for SQL Server 2008. For SQL2005:
        o sysssispackagefolders =&gt; sysdtspackagefolders90
        o sysssispackages =&gt; sysdtspackages90
*/
</span><span style="color: blue">with </span>ChildFolders
<span style="color: blue">as
</span><span style="color: gray">(
    </span><span style="color: blue">select </span>PARENT<span style="color: gray">.</span>parentfolderid<span style="color: gray">, </span>PARENT<span style="color: gray">.</span>folderid<span style="color: gray">, </span>PARENT<span style="color: gray">.</span>foldername<span style="color: gray">,
        </span><span style="color: magenta">cast</span><span style="color: gray">(</span><span style="color: red">'' </span><span style="color: blue">as sysname</span><span style="color: gray">) </span><span style="color: blue">as </span>RootFolder<span style="color: gray">,
        </span><span style="color: magenta">cast</span><span style="color: gray">(</span>PARENT<span style="color: gray">.</span>foldername <span style="color: blue">as varchar</span><span style="color: gray">(</span><span style="color: magenta">max</span><span style="color: gray">)) </span><span style="color: blue">as </span>FullPath<span style="color: gray">,
        </span>0 <span style="color: blue">as </span>Lvl
    <span style="color: blue">from </span>msdb<span style="color: gray">.</span>dbo<span style="color: gray">.</span>sysssispackagefolders PARENT
    <span style="color: blue">where </span>PARENT<span style="color: gray">.</span>parentfolderid <span style="color: gray">is null
    </span><span style="color: blue">UNION </span><span style="color: gray">ALL
    </span><span style="color: blue">select </span>CHILD<span style="color: gray">.</span>parentfolderid<span style="color: gray">, </span>CHILD<span style="color: gray">.</span>folderid<span style="color: gray">, </span>CHILD<span style="color: gray">.</span>foldername<span style="color: gray">,
        </span><span style="color: blue">case </span>ChildFolders<span style="color: gray">.</span>Lvl
            <span style="color: blue">when </span>0 <span style="color: blue">then </span>CHILD<span style="color: gray">.</span>foldername
            <span style="color: blue">else </span>ChildFolders<span style="color: gray">.</span>RootFolder
        <span style="color: blue">end as </span>RootFolder<span style="color: gray">,
        </span><span style="color: magenta">cast</span><span style="color: gray">(</span>ChildFolders<span style="color: gray">.</span>FullPath <span style="color: gray">+ </span><span style="color: red">'/' </span><span style="color: gray">+ </span>CHILD<span style="color: gray">.</span>foldername <span style="color: blue">as varchar</span><span style="color: gray">(</span><span style="color: magenta">max</span><span style="color: gray">))
            </span><span style="color: blue">as </span>FullPath<span style="color: gray">,
        </span>ChildFolders<span style="color: gray">.</span>Lvl <span style="color: gray">+ </span>1 <span style="color: blue">as </span>Lvl
    <span style="color: blue">from </span>msdb<span style="color: gray">.</span>dbo<span style="color: gray">.</span>sysssispackagefolders CHILD
        <span style="color: gray">inner join </span>ChildFolders <span style="color: blue">on </span>ChildFolders<span style="color: gray">.</span>folderid <span style="color: gray">= </span>CHILD<span style="color: gray">.</span>parentfolderid
<span style="color: gray">)
</span><span style="color: blue">select </span>F<span style="color: gray">.</span>RootFolder<span style="color: gray">, </span>F<span style="color: gray">.</span>FullPath<span style="color: gray">, </span>P<span style="color: gray">.</span>name <span style="color: blue">as </span>PackageName<span style="color: gray">,
    </span>P<span style="color: gray">.</span><span style="color: blue">description as </span>PackageDescription<span style="color: gray">, </span>P<span style="color: gray">.</span>packageformat<span style="color: gray">, </span>P<span style="color: gray">.</span>packagetype<span style="color: gray">,
    </span>P<span style="color: gray">.</span>vermajor<span style="color: gray">, </span>P<span style="color: gray">.</span>verminor<span style="color: gray">, </span>P<span style="color: gray">.</span>verbuild<span style="color: gray">, </span>P<span style="color: gray">.</span>vercomments<span style="color: gray">,
    </span><span style="color: magenta">cast</span><span style="color: gray">(</span><span style="color: magenta">cast</span><span style="color: gray">(</span>P<span style="color: gray">.</span>packagedata <span style="color: blue">as varbinary</span><span style="color: gray">(</span><span style="color: magenta">max</span><span style="color: gray">)) </span><span style="color: blue">as xml</span><span style="color: gray">) </span><span style="color: blue">as </span>PackageData
<span style="color: blue">from </span>ChildFolders F
    <span style="color: gray">inner join </span>msdb<span style="color: gray">.</span>dbo<span style="color: gray">.</span>sysssispackages P <span style="color: blue">on </span>P<span style="color: gray">.</span>folderid <span style="color: gray">= </span>F<span style="color: gray">.</span>folderid
<span style="color: blue">order by </span>F<span style="color: gray">.</span>FullPath <span style="color: blue">asc</span><span style="color: gray">, </span>P<span style="color: gray">.</span>name <span style="color: blue">asc</span><span style="color: gray">;</span></pre>
<p>The query uses a recursive CTE (<a title="BOL 2008: Using Common Table Expressions" href="http://msdn.microsoft.com/en-us/library/ms190766.aspx">Common Table Expression</a>) to get data out of a system table called <a title="BOL 2008: sysssispackagefolders (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms189477.aspx">sysssispackagefolders</a>, located in the MSDB system database.&#160; The CTE gives us a list of all folders stored in the database and at the same time uses the hierarchical structure of the table to build the <em>FullPath</em> and the <em>Lvl</em> columns.</p>
<p><strong>Note:</strong> the <a title="BOL 2008: CAST and CONVERT (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms187928.aspx">CAST()</a> calls are needed because the data type of the <em>foldername</em> column is <a title="BOL 2008: Using Special Data Types" href="http://msdn.microsoft.com/en-us/library/ms191240.aspx">sysname</a>.&#160; And sysname does not implicitly convert to varchar, which is needed for the concatenation building the <em>FullPath</em> column.</p>
<p>The CTE is joined with another system table called <a title="BOL 2008: sysssispackages (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms181582.aspx">sysssispackages</a>, also located in MSDB.&#160; Not all columns are being retrieved from that table but I believe I&#8217;ve selected the most important ones.&#160; Have a look in the Books Online for more info on the columns available.</p>
<p>There’s one column however on which I’d like to add some additional info myself.&#160; That column is called <em>packagedata</em> and it contains the actual SSIS package.&#160; The data type of this column is <a title="BOL 2008: ntext, text, and image (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms187993.aspx">image</a>, not sure why because after all, an SSIS package (or .dtsx file for that matter) is pure XML.&#160; So why isn’t it stored as XML? <strike> If anyone knows the reason: post a comment!</strike></p>
<p><strong>Update:</strong> since I wrote the above paragraph I’ve come across the answer myself.&#160; The reason that the XML is not stored as xml datatype is because of the overhead that this would cause.&#160; So there you go, use image instead of xml if you’re not going to query the xml structure itself.</p>
<p>Anyway, as you can see in the query, to get it converted from image to XML you need to go through varbinary.&#160; The image datatype cannot convert directly to XML.&#160; See the Books Online here on what casts are allowed: <a title="http://msdn.microsoft.com/en-us/library/ms187928.aspx" href="http://msdn.microsoft.com/en-us/library/ms187928.aspx">http://msdn.microsoft.com/en-us/library/ms187928.aspx</a></p>
<p><strong>Note for SQL Server 2005 users:</strong> as mentioned in the query’s comments, these tables don’t exist in SQL Server 2005.&#160; Well, actually they do, they just have different names.&#160; See the comment in the code for their equivalent.</p>
<p>To finish off I&#8217;ll show you what the results look like when executing the query on my test system.&#160; But first, following screenshot shows all deployed packages as reported by the Management Studio.&#160; As you can see, two packages are deployed to the File System.&#160; These two packages were shown earlier in the first screenshot.&#160; Some other packages have been deployed to the MSDB database.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Object Explorer showing all deployed SSIS packages" border="0" alt="Object Explorer showing all deployed SSIS packages" src="http://blog.hoegaerden.be/wp-content/uploads/image141.png" width="329" height="306" /></p>
<p>And here are the results of the query:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image143.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="A list of all SSIS packages deployed to my SQL Server 2008 MSDB database" border="0" alt="A list of all SSIS packages deployed to my SQL Server 2008 MSDB database" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb37.png" width="692" height="84" /></a></p>
<p>To be honest, I added a little filter to keep the results clean.&#160; The <a title="BOL 2008: Introducing the Data Collector" href="http://msdn.microsoft.com/en-us/library/bb677248.aspx">Data Collector</a>, a new feature of SQL Server 2008, also uses some packages so I’ve filtered those out by adding a WHERE clause to the SELECT statement at the bottom of the full query:</p>
<pre class="code"><span style="color: blue">select </span>F<span style="color: gray">.</span>RootFolder<span style="color: gray">, </span>F<span style="color: gray">.</span>FullPath<span style="color: gray">, </span>P<span style="color: gray">.</span>name <span style="color: blue">as </span>PackageName<span style="color: gray">,
    </span>P<span style="color: gray">.</span><span style="color: blue">description as </span>PackageDescription<span style="color: gray">, </span>P<span style="color: gray">.</span>packageformat<span style="color: gray">, </span>P<span style="color: gray">.</span>packagetype<span style="color: gray">,
    </span>P<span style="color: gray">.</span>vermajor<span style="color: gray">, </span>P<span style="color: gray">.</span>verminor<span style="color: gray">, </span>P<span style="color: gray">.</span>verbuild<span style="color: gray">, </span>P<span style="color: gray">.</span>vercomments<span style="color: gray">,
    </span><span style="color: magenta">cast</span><span style="color: gray">(</span><span style="color: magenta">cast</span><span style="color: gray">(</span>P<span style="color: gray">.</span>packagedata <span style="color: blue">as varbinary</span><span style="color: gray">(</span><span style="color: magenta">max</span><span style="color: gray">)) </span><span style="color: blue">as xml</span><span style="color: gray">) </span><span style="color: blue">as </span>PackageData
<span style="color: blue">from </span>ChildFolders F
    <span style="color: gray">inner join </span>msdb<span style="color: gray">.</span>dbo<span style="color: gray">.</span>sysssispackages P <span style="color: blue">on </span>P<span style="color: gray">.</span>folderid <span style="color: gray">= </span>F<span style="color: gray">.</span>folderid
<span style="color: blue">where </span>F<span style="color: gray">.</span>RootFolder <span style="color: gray">&lt;&gt; </span><span style="color: red">'Data Collector'
</span><span style="color: blue">order by </span>F<span style="color: gray">.</span>FullPath <span style="color: blue">asc</span><span style="color: gray">, </span>P<span style="color: gray">.</span>name <span style="color: blue">asc</span><span style="color: gray">;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>If you’ve been paying attention, you’ve noticed that the two packages deployed to the File System are not mentioned in the output of the query, as expected.</p>
<p>Now that you know how to list your packages, <a title="Recursively Delete SSIS Folder" href="http://blog.hoegaerden.be/2010/02/28/recursively-delete-ssis-folder/" target="_blank">check out my article on deleting them</a>.</p>
<p>That’s all for now folks, have fun!</p>
<p><strong>References</strong></p>
<p><a title="BOL 2008: Tutorial: Creating a Simple ETL Package" href="http://msdn.microsoft.com/en-us/library/ms169917.aspx">BOL 2008: Tutorial: Creating a Simple ETL Package</a></p>
<p><a title="BOL 2008: sysssispackagefolders (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms189477.aspx">BOL 2008: sysssispackagefolders (Transact-SQL)</a></p>
<p><a title="BOL 2008: sysssispackages (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms181582.aspx">BOL 2008: sysssispackages (Transact-SQL)</a></p>
<p><a title="BOL 2008: Recursive Queries Using Common Table Expressions" href="http://msdn.microsoft.com/en-us/library/ms186243.aspx">BOL 2008: Recursive Queries Using Common Table Expressions</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2010/01/10/list-all-ssis-packages-deployed-on-your-integration-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SSMS Showing Incorrect Version Numbers In Object Explorer</title>
		<link>http://blog.hoegaerden.be/2010/01/10/ssms-showing-incorrect-version-numbers-in-object-explorer/</link>
		<comments>http://blog.hoegaerden.be/2010/01/10/ssms-showing-incorrect-version-numbers-in-object-explorer/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 23:21:23 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Management Studio]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Integration Services 2008]]></category>
		<category><![CDATA[Reporting Services 2008]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/01/10/ssms-showing-incorrect-version-numbers-in-object-explorer/</guid>
		<description><![CDATA[Ever since I upgraded to SQL Server 2008 Service Pack 1 I noticed that the Management Studio was reporting incorrect version numbers when connected to Integration or Reporting Services.&#160; This incorrect version number is located to the right of the server instance in the Object Explorer.
As usual, a picture says so much more than … [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since I upgraded to SQL Server 2008 Service Pack 1 I noticed that the Management Studio was reporting incorrect version numbers when connected to Integration or Reporting Services.&#160; This incorrect version number is located to the right of the server instance in the Object Explorer.</p>
<p>As usual, a picture says so much more than … :</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Object Explorer showing wrong version numbers" border="0" alt="Object Explorer showing wrong version numbers" src="http://blog.hoegaerden.be/wp-content/uploads/image139.png" width="436" height="116" /> </p>
<p>As I have <a title="10.0.2531.0" href="http://blog.hoegaerden.be/2009/04/12/10025310/" target="_blank">posted earlier</a>, 10.0.2531 is the version number for SP1, while 10.0.1600 is the original RTM version number.</p>
<p>I never really spent time looking for an answer to this.&#160; It was obviously a bug but I could live with it and someone else would probably already have filed it as being a bug.&#160; So recently I came across <a title="SSIS 2008 - Beware of incorrect version stamp in SSMS" href="http://www.ssistalk.com/2010/01/04/ssis-2008-beware-of-incorrect-version-stamp-in-ssms/" target="_blank">a post by Phil Brammer</a> that mentioned this issue.&#160; This post got a comment from <a title="SSIS Team Blog - A blog about SQL Server Integration Services (SSIS) from a developer on the team." href="http://blogs.msdn.com/mattm/" target="_blank">Matt Masson</a>, a developer on the SSIS team.&#160; Have a look at the comment but in short: the version numbers that are being shown in the Object Explorer are actually the version numbers of the service’s .exe file!&#160; And SSMS is now showing the wrong number because these files didn’t get an update in SP1.</p>
<p>After a little search I found the <a title="Incorrect Version (build) number in SSMS with SSRS and SSIS" href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=422562&amp;wa=wsignin1.0" target="_blank">bug report on Microsoft Connect</a>, reported on March 11, 2009, by <a title="Dan English&#39;s BI Blog" href="http://denglishbi.spaces.live.com/" target="_blank">Dan English</a>.&#160; Its status is Fixed but it seems that it isn’t.&#160; At least, looking at the comments, <a title="Cumulative Update Package 5 for SQL Server 2008 Service Pack 1" href="http://support.microsoft.com/kb/975977/LN/" target="_blank">CU5 (Cumulative Update) for SQL Server 2008 SP1</a> is still showing the problem.&#160; So I guess you could go over to the Connect page and click on that Yes button if you’re interested in seeing this fixed.&#160; After all, it could be quite misleading to novice DB guys and gals…</p>
<p>On this same subject, there’s another <a title="Reporting Services: What’s my version?" href="http://blogs.msdn.com/psssql/archive/2009/09/30/reporting-services-what-s-my-version.aspx" target="_blank">interesting post by Adam W. Saxton</a>, a member of the Microsoft SQL Server Escalation Services Team.&#160; In this post he takes a closer look at the SQL Server 2008 Reporting Services version number after having installed CU2.</p>
<p><strong>Conclusion:</strong> if you need to find out what version your server is running, do not rely on the version numbers that you see in the Object Explorer.&#160; As Adam explained, one way is to look at the version numbers of the files that were included in the upgrade.&#160; But that may a bit of an overkill.&#160; My favorite way, assuming that all components of the SQL Server installation have been upgraded to the same version, is to use the following query:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">SELECT</span> @@VERSION;</pre>
</div>
<p>&#160;</p>
<p>On my machine that comes back with the following result:</p>
<blockquote>
<p>Microsoft SQL Server 2008 (SP1) &#8211; 10.0.2531.0 (Intel X86)&#160;&#160; Mar 29 2009 10:27:29&#160;&#160; Copyright (c) 1988-2008 Microsoft Corporation&#160; Developer Edition on Windows NT 5.1 &lt;X86&gt; (Build 2600: Service Pack 3) </p>
</blockquote>
<p>And remember, have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2010/01/10/ssms-showing-incorrect-version-numbers-in-object-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Quick SSIS tip when working with wide tables</title>
		<link>http://blog.hoegaerden.be/2009/09/03/quick-ssis-tip-when-working-with-wide-tables/</link>
		<comments>http://blog.hoegaerden.be/2009/09/03/quick-ssis-tip-when-working-with-wide-tables/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 20:00:55 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[Business Intelligence Development Studio]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2009/09/03/quick-ssis-tip-when-working-with-wide-tables/</guid>
		<description><![CDATA[If you’ve ever needed to load a wide table, for instance one that consists of about 250 columns, you may have come to the conclusion that some manipulations in your SSIS package take forever.  Here’s a quick tip how to speed up your package development.
This tip is actually quite generic and applicable to daily Windows [...]]]></description>
			<content:encoded><![CDATA[<p>If you’ve ever needed to load a wide table, for instance one that consists of about 250 columns, you may have come to the conclusion that some manipulations in your SSIS package take forever.  Here’s a quick tip how to speed up your package development.</p>
<p>This tip is actually quite generic and applicable to daily Windows use.  It’s just that sometimes you forget about the most simple things because you’re used to a different way of working.  Why make it easy when difficult works fine, right?  Well, maybe not.</p>
<p>Okay, here it goes: <strong>don’t forget that you’ve got a keyboard, do not always use the mouse!</strong> The Business Intelligence Development Studio offers a very graphical way of designing your data flow (or control flow for that matter) but sometimes it’s really faster to use the keyboard.</p>
<p>An example.  Imagine the Derived Column Transformation.  To avoid typographical errors you want to select a column name from the tree view on the left in the Derived Column Transformation Editor.  And then you discover that the list of column names is not ordered alphabetically, and on top of that, there’s not way to rearrange them!  Good luck finding your column.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Derived Column Transformation Editor" src="http://blog.hoegaerden.be/wp-content/uploads/image67.png" border="0" alt="Derived Column Transformation Editor" width="409" height="372" /></p>
<p>And then you remember that you’ve got a keyboard.  By <strong>typing the first letters</strong> of the column name, the selected item will jump down to the first match.  Isn’t that a great invention?!  In the screenshot above I typed “pu” and it selected PurchaseOrderNumber, which is about 32 columns down from the top.</p>
<p>This tip not only works in our Derived Column Transformation but in any screen where a similar tree view appears, such as in the “Inputs and Outputs Properties” tab of the Advanced Editor of an OLE DB Source:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image68.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Advanced Editor of OLE DB Source" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb1.png" border="0" alt="Advanced Editor of OLE DB Source" width="502" height="535" /></a></p>
<p>This can be useful if you need to tell the component that you’ve ordered the data on certain columns.  And why on earth would you want to do that, you may ask yourself.  Well, there are certain components that expect the data to be ordered, such as the Merge item.</p>
<p>If you apply this tip whenever you need to locate something in a tree view, you’ll find that your live has become just a bit easier.</p>
<p>And if you’re not satisfied with the way of working as described above, there’s always the XML!  That’s right, just right-click on your package in the Solution Explorer and select View Code.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image69.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Context menu on package in Solution Explorer" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb2.png" border="0" alt="Context menu on package in Solution Explorer" width="319" height="167" /></a></p>
<p>Then you’ll discover that a .dtsx file is made up completely of XML.  If you spend some time examining the XML code, you’ll probably find what you’re looking for.</p>
<p>As an example let’s say we want to locate our PurchaseOrderNumber from earlier and change its SortKeyPosition property to 1 (which means the data coming in is ordered by PurchaseOrderNumber).  So I open the XML and scroll down a bit.  I recognize a component which I’ve named “OLE_SRC Wide Table”:</p>
<div class="code"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">component</span><span style="color: #ff0000;"> id</span><span style="color: #0000ff;">=&#8221;1&#8243;</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">=&#8221;OLE_SRC Wide Table&#8221;</span><span style="color: #ff0000;"> </span> …</div>
<div class="code"></div>
<p>I also recognize my SELECT statement.  Scrolling down a bit further I see the</p>
<div class="code"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">outputs</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"> </span></div>
<p>followed by a bunch of outputColumn items.  I put the cursor at the &lt;outputs&gt; line and hit CTRL-F.  Then I type “pur” and hit ENTER.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image70.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Find and Replace window in dtsx XML" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb3.png" border="0" alt="Find and Replace window in dtsx XML" width="483" height="461" /></a></p>
<p>The selection jumps to the column that we’re after.  I close the Find and Replace window and scroll to the right to find the sortKeyPosition property and I update its value to 1.</p>
<p>To confirm that this is working I open up the Advanced Editor again and locate our column.  SortKeyPosition is set to 1!</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image71.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SortKeyPosition has been updated through XML" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb4.png" border="0" alt="SortKeyPosition has been updated through XML" width="258" height="120" /></a></p>
<p>I hope that with this I showed you that sometimes it’s interesting to think about what you’re actually doing and try to find a way to do it better, and faster.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2009/09/03/quick-ssis-tip-when-working-with-wide-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
