<?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; SQL Server</title>
	<atom:link href="http://blog.hoegaerden.be/category/sqlserver/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>Wed, 01 Feb 2012 16:15:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>SSIS: Highlight Unused Package Variables</title>
		<link>http://blog.hoegaerden.be/2012/01/09/ssis-highlight-unused-package-variables/</link>
		<comments>http://blog.hoegaerden.be/2012/01/09/ssis-highlight-unused-package-variables/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 17:48:13 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[BIDS]]></category>
		<category><![CDATA[BIDS Helper]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2012/01/09/ssis-highlight-unused-package-variables/</guid>
		<description><![CDATA[Quick post to ask a moment of your time. Have you ever wanted a feature in the BIDS to quickly identify package variables which have become obsolete?  Well, I’ve been involved in the cleanup of existing packages and I can tell you, that feature would be very handy! After a search on the internet, it [...]]]></description>
			<content:encoded><![CDATA[<p>Quick post to ask a moment of your time.</p>
<p>Have you ever wanted a feature in the BIDS to quickly identify package variables which have become obsolete?  Well, I’ve been involved in the cleanup of existing packages and I can tell you, that feature would be very handy!</p>
<p>After a search on the internet, it turns out that one of the planned features for the <a title="BIDS Helper" href="http://bidshelper.codeplex.com/" target="_blank">BIDS Helper</a> contains exactly that.  The request is a bit wider than what I need, but at least “highlight unused variables” is part of it.</p>
<p>All I’m asking now is just a minute of your time to vote for <a title="SSIS 2008 - &quot;Find all references&quot; feature for variables" href="http://bidshelper.codeplex.com/workitem/29510" target="_blank">that feature request</a>.</p>
<p>Have fun, and thank you!</p>
<p>Valentino.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2012%2F01%2F09%2Fssis-highlight-unused-package-variables%2F&amp;title=SSIS%3A%20Highlight%20Unused%20Package%20Variables" id="wpa2a_2"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2012/01/09/ssis-highlight-unused-package-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Posting An Issue To Microsoft Connect</title>
		<link>http://blog.hoegaerden.be/2012/01/04/posting-an-issue-to-microsoft-connect/</link>
		<comments>http://blog.hoegaerden.be/2012/01/04/posting-an-issue-to-microsoft-connect/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 11:21:05 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[Microsoft Connect]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2012/01/04/posting-an-issue-to-microsoft-connect/</guid>
		<description><![CDATA[I’ve been a user of the Microsoft Connect site for several years now.  A regular user who now and then casts an Up vote or clicks the “I can reproduce it!” link.  Not as a content poster.  Well, I did post some comments in the past, but I never filed an issue or suggestion. So, [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been a user of the <a title="Microsoft Connect" href="https://connect.microsoft.com/" target="_blank">Microsoft Connect</a> site for several years now.  A regular user who now and then casts an Up vote or clicks the “I can reproduce it!” link.  Not as a content poster.  Well, I did post some comments in the past, but I never filed an issue or suggestion.</p>
<p>So, a couple of weeks ago I decided to post my first bug to Microsoft Connect, an issue which I had discovered in SQL Server 2012 RC0.  Because this process took me more time than I’d expected, I‘m now blogging about my experience.</p>
<p>The hardest part about the whole experience was finding the actual page that needs to be used to enter and submit the content.</p>
<h2>Submitting Content To Microsoft Connect</h2>
<p>Are you in for a ride on the Connect site?  Here we go!</p>
<h3>Step 1: Search For Your Product on The Connect Home Page</h3>
<h3><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="Enter a search term on Microsoft Connect to locate your favorite product" src="http://blog.hoegaerden.be/wp-content/uploads/image439.png" border="0" alt="Enter a search term on Microsoft Connect to locate your favorite product" width="700" height="430" /></h3>
<p>On the Home page, enter a search term with which you can locate your favorite product.  If you’re not signed in yet, do that first.</p>
<h3>Step 2: Click To Participate</h3>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image440.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="On the search results, click the Participate link next to your favorite product." src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb104.png" border="0" alt="On the search results, click the Participate link next to your favorite product." width="700" height="261" /></a></p>
<p>Once the search engine has produced the output, locate your favorite product and click the <strong>Participate</strong> action next to it.</p>
<h3>Step 3: Submit Product Feedback</h3>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="Click Submit Product Feedback to submit product feedback." src="http://blog.hoegaerden.be/wp-content/uploads/image441.png" border="0" alt="Click Submit Product Feedback to submit product feedback." width="700" height="692" /></p>
<p>After clicking Participate, the following overwhelming screen appears.  The link that you’re looking for is called <strong>Submit Product Feedback</strong>.</p>
<h3>Step 4: The Feedback Center</h3>
<p>After clicking Submit Product Feedback, you end up at the <a title="Feedback Center" href="https://connect.microsoft.com/SQLServer/Feedback" target="_blank">Feedback Center</a>.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Do not use the Submit link, use Search first to check if your issue already exists." src="http://blog.hoegaerden.be/wp-content/uploads/image442.png" border="0" alt="Do not use the Submit link, use Search first to check if your issue already exists." width="700" height="557" /></p>
<p>Looking at the screen above, you’d think that the yellow Submit Feedback button can be used to open the page where you’d need to enter the bug details.  Well, it doesn’t…</p>
<p>You need to search for your issue first, to ensure it doesn’t exist already.</p>
<h3>Step 5: The Submit Feedback Button Has Been Found, Eureka!</h3>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The Submit Feedback button on the Product Search Results screen." src="http://blog.hoegaerden.be/wp-content/uploads/image443.png" border="0" alt="The Submit Feedback button on the Product Search Results screen." width="700" height="259" /></p>
<p>After you’ve performed the search for your issue, you get to the following page above.  Finally, on that page you can click a real <strong>Submit Feedback</strong> button that will bring you to the Select Feedback Form page.</p>
<h3>Step 6: Select Your Feedback Form Of Choice</h3>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Select SQL Server Bug Form to file a SQL Server issue, or SQL Server Suggestion Form for a suggestion." src="http://blog.hoegaerden.be/wp-content/uploads/image444.png" border="0" alt="Select SQL Server Bug Form to file a SQL Server issue, or SQL Server Suggestion Form for a suggestion." width="550" height="198" /></p>
<p>On the <a title="Select Feedback Form" href="https://connect.microsoft.com/SQLServer/feedback/CreateFeedback.aspx" target="_blank">Select Feedback Form</a> page, select <strong>SQL Server Bug Form</strong> to file a SQL Server issue, or select<strong> SQL Server Suggestion Form</strong> to enter a suggestion.</p>
<h3>Step 7: Fill Out The Textboxes</h3>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The &quot;Submit A Bug&quot; Form for SQL Server." src="http://blog.hoegaerden.be/wp-content/uploads/image445.png" border="0" alt="The &quot;Submit A Bug&quot; Form for SQL Server." width="700" height="529" /></p>
<p>Finally, the page we’ve been trying to locate when we started the adventure, quest accomplished!  With this new knowledge, we can now skip directly to step 6 through the following link: <a title="Select Feedback Form" href="https://connect.microsoft.com/SQLServer/feedback/CreateFeedback.aspx" target="_blank">Select Feedback Form</a></p>
<p><em>Disclaimer: please ensure that you’re not creating duplicate bugs or suggestions, but use whatever search engine your prefer to achieve that goal!</em></p>
<p>So, here’s my New Year’s present to all of you!  And remember: have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="Microsoft Connect" href="https://connect.microsoft.com/" target="_blank">Microsoft Connect</a></p>
<p><a title="Feedback Center" href="https://connect.microsoft.com/SQLServer/Feedback" target="_blank">Feedback Center</a></p>
<p><a title="Select Feedback Form" href="https://connect.microsoft.com/SQLServer/feedback/CreateFeedback.aspx" target="_blank">Select Feedback Form</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2012%2F01%2F04%2Fposting-an-issue-to-microsoft-connect%2F&amp;title=Posting%20An%20Issue%20To%20Microsoft%20Connect" id="wpa2a_4"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2012/01/04/posting-an-issue-to-microsoft-connect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where&#8217;s My SSIS Toolbox?!</title>
		<link>http://blog.hoegaerden.be/2011/12/22/wheres-my-ssis-toolbox/</link>
		<comments>http://blog.hoegaerden.be/2011/12/22/wheres-my-ssis-toolbox/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 15:25:21 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2011/12/22/wheres-my-ssis-toolbox/</guid>
		<description><![CDATA[When I opened an existing SSIS project in the new SQL Server 2012 RC0, I came to an interesting discovery: an empty Toolbox pane!  Even with an SSIS package open in the designer.  Hmm, that’s funny!  So where are my SSIS components? Take a good look at the following screenshot: That’s right, they are not [...]]]></description>
			<content:encoded><![CDATA[<p>When I opened an existing SSIS project in the new SQL Server 2012 RC0, I came to an interesting discovery: an empty Toolbox pane!  Even with an SSIS package open in the designer.  Hmm, that’s funny!  So where are my SSIS components?</p>
<p>Take a good look at the following screenshot:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="The Toolbox is no longer the SSIS Toolbox but the new SSIS Toolbox is!" src="http://blog.hoegaerden.be/wp-content/uploads/image435.png" border="0" alt="The Toolbox is no longer the SSIS Toolbox but the new SSIS Toolbox is!" width="436" height="534" /></p>
<p>That’s right, they are not in the Toolbox anymore but in the <strong>SSIS Toolbox</strong> instead.  This new toolbox is a bit different from the old one.  Besides the grouping of components that has changed, the most important change is that it will automatically detect any custom components.  You no longer need to right-click, select Choose Items, go fetch a coffee, wait until it cools down a bit, drink it and finally … select your custom component.  No, you’ll have to find another reason to get that coffee shot.  Actually, that’s not entirely true: you still need to right-click and then click Refresh Toolbox and then the custom components will be shown.</p>
<p>Another difference is that it’s split in two parts.  The bottom half of the pane now contains a description of the selected item, including a link that should lead to samples and a link to the Books Online.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="The new SSIS Toolbox shows a description of the selected=" src="http://blog.hoegaerden.be/wp-content/uploads/image436.png" border="0" alt="The new SSIS Toolbox shows a description of the selected=" width="233" height="252" /></p>
<p>Out of curiosity I tried the <strong>Find Samples</strong> link a couple of times, but for now it doesn’t seem to deliver much content:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Not many results through Find Samples link" src="http://blog.hoegaerden.be/wp-content/uploads/image437.png" border="0" alt="Not many results through Find Samples link" width="700" height="325" /></p>
<p>Okay, so one thing remains: how do you open the new SSIS Toolbox pane?  According to the Books Online it should be opened automatically when you open an existing project.  Well, apparently not all the time!</p>
<p>The first place I’d look is in the View menu.  But alas, SSIS Toolbox is not one of the menu items.  Not even in the Other Windows submenu.  Why oh why?!</p>
<p>Long story short: do you see those two buttons in the below screenshot?  They’re new!</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="Package designer has gotten two new buttons" src="http://blog.hoegaerden.be/wp-content/uploads/image438.png" border="0" alt="Package designer has gotten two new buttons" width="508" height="80" /></p>
<p>The first button leads to the Variables pane, the second button will open the SSIS Toolbox.  Good to know isn’t it?!</p>
<p>Further investigation led me to the following: according to the Books Online, the SSIS Toolbox item should actually be located in the View &gt; Other Windows menu.  As that is not the case and I think it’s only logical to have that pane added to the View menu as well, I’ve filed a bug on Microsoft Connect.  <a title="Connect: SQL Server 2012 RC0 - SSIS Toolbox menu item is missing" href="http://connect.microsoft.com/SQLServer/feedback/details/714530/sql-server-2012-rc0-ssis-toolbox-menu-item-is-missing" target="_blank">Go ahead and vote</a>!</p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="SSIS Toolbox" href="http://msdn.microsoft.com/en-us/library/ff929137(v=sql.110).aspx" target="_blank">SSIS Toolbox</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2011%2F12%2F22%2Fwheres-my-ssis-toolbox%2F&amp;title=Where%26rsquo%3Bs%20My%20SSIS%20Toolbox%3F%21" id="wpa2a_6"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2011/12/22/wheres-my-ssis-toolbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Funny SSIS Container</title>
		<link>http://blog.hoegaerden.be/2011/12/15/the-funny-ssis-container/</link>
		<comments>http://blog.hoegaerden.be/2011/12/15/the-funny-ssis-container/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 18:39:16 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SQL Server 2012]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2011/12/15/the-funny-ssis-container/</guid>
		<description><![CDATA[A couple of days ago I came across a funny and weird object in the Control Flow.  It looked like this: As you can see, this container looks a bit similar to the Sequence Container but the Sequence Container has a different icon.  Also, this container does not have any connectors sticking out.  I’m currently [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago I came across a funny and weird object in the Control Flow.  It looked like this:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="Group Tasks" src="http://blog.hoegaerden.be/wp-content/uploads/image430.png" border="0" alt="Group Tasks" width="168" height="201" /></p>
<p>As you can see, this container looks a bit similar to the Sequence Container but the Sequence Container has a different icon.  Also, this container does not have any connectors sticking out.  I’m currently involved in a 2005 &gt; 2008 migration project, which is how I came across this container in the first place, and thus I really needed to find out what this object actually is.  So I started to investigate.  Unfortunately the properties were not very helpful:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="Group does not have any properties" src="http://blog.hoegaerden.be/wp-content/uploads/image431.png" border="0" alt="Group does not have any properties" width="408" height="170" /></p>
<p>No properties, nothing at all, not even an object name.  Then I started to scan the <strong>Toolbox</strong> pane for the icon.  Guess what?  Right, nothing either!  Is this some kind of custom control??</p>
<p>The logical next step is to perform some internet searches and I found the answer: this is standard SSIS functionality that exists since SQL Server 2005!  WTF! (is what I thought at that moment)</p>
<h2>The Grouping Container</h2>
<p>In the <strong>Control Flow</strong>, if you right-click on at least one task, you get the following options:</p>
<p><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://blog.hoegaerden.be/wp-content/uploads/image432.png" border="0" alt="image" width="210" height="183" /></p>
<p>And when you select <strong>Group</strong>, you’ll get that group container around the selected objects, allowing you to collapse the items.  Well, okay, I’ll probably still never use it now that I know that it exists.  Which is possibly the reason that I don’t know about it in the first place.</p>
<h3>How Not To Use It</h3>
<p>Using that grouping functionality you can end up with some weird-looking flows:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="How not to use the group tasks functionality" src="http://blog.hoegaerden.be/wp-content/uploads/image433.png" border="0" alt="How not to use the group tasks functionality" width="700" height="346" /></p>
<p>What have we learned?  That even with years of SSIS experience, it’s still possible to discover “new” functionality.</p>
<p>And speaking of new functionality, that brings us to SQL Server 2012 (formerly known as Denali).</p>
<h3>Grouping In SQL Server 2012</h3>
<p>As of <strong>SQL Server 2012</strong>, not only will you be able to group tasks in the Control Flow.  You can also <strong>group components in the Data Flow</strong>.  Now that may prove more interesting than its Control Flow counterpart.  Why?  Because in the Control Flow chances are that you’ve already grouped your tasks using some Sequence Containers while you don’t have any containers in the Data Flow.</p>
<p>Here’s what it looks like:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="SQL Server 2012 allows grouping components in the Data Flow" src="http://blog.hoegaerden.be/wp-content/uploads/image434.png" border="0" alt="SQL Server 2012 allows grouping components in the Data Flow" width="284" height="312" /></p>
<p>As you can see, the icon is now gone.  But the properties pane is still totally empty with the group control selected.  Oh well…</p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="How to: Group Tasks and Containers in a Control Flow" href="http://msdn.microsoft.com/en-us/library/ms137981(v=SQL.90).aspx" target="_blank">How to: Group Tasks and Containers in a Control Flow</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2011%2F12%2F15%2Fthe-funny-ssis-container%2F&amp;title=The%20Funny%20SSIS%20Container" id="wpa2a_8"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2011/12/15/the-funny-ssis-container/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enhanced Duplicate Key Error Message</title>
		<link>http://blog.hoegaerden.be/2011/11/27/enhanced-duplicate-key-error-message/</link>
		<comments>http://blog.hoegaerden.be/2011/11/27/enhanced-duplicate-key-error-message/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 15:30:09 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2011/11/27/enhanced-duplicate-key-error-message/</guid>
		<description><![CDATA[I came across an interesting little enhancement which I’d like to share with you.  I’m sure you’re all familiar with the following error message: Msg 2601, Level 14, State 1, Line 4 Cannot insert duplicate key row in object &#8216;dbo.#t&#8217; with unique index &#8216;PK_Unique&#8217;. That’s right, the “hey, you’re inserting junk, stop that right now!” [...]]]></description>
			<content:encoded><![CDATA[<p>I came across an interesting little enhancement which I’d like to share with you.  I’m sure you’re all familiar with the following error message:</p>
<blockquote><p>Msg 2601, Level 14, State 1, Line 4<br />
Cannot insert duplicate key row in object &#8216;dbo.#t&#8217; with unique index &#8216;PK_Unique&#8217;.</p></blockquote>
<p>That’s right, the “hey, you’re inserting junk, stop that right now!” message.</p>
<p>However, earlier this week I encountered a variation of that error in our ETL logs:</p>
<blockquote><p>Msg 2601, Level 14, State 1, Line 3<br />
Cannot insert duplicate key row in object &#8216;dbo.#t&#8217; with unique index &#8216;PK_Unique&#8217;. <strong>The duplicate key value is (1, 2).</strong></p></blockquote>
<p>I’m sure I don’t need to explain how useful that extra sentence can be, right?  So, then I started digging because obviously I want that error to always include the offending values.</p>
<p>Recently our database back-end servers have been replaced with new machines running SQL Server 2008 R2 SP1.  And indeed, as of R2 SP1, this error message has gotten an upgrade!</p>
<p>If you want to check for yourself, the following code snippet can be used to generate the error:</p>
<pre class="code"><span style="color: blue;">create table </span>#t <span style="color: gray;">(</span>PK1 <span style="color: blue;">int</span><span style="color: gray;">, </span>PK2 <span style="color: blue;">int</span><span style="color: gray;">);
</span><span style="color: blue;">create unique index </span>PK_Unique <span style="color: blue;">on </span>#t<span style="color: gray;">(</span>PK1<span style="color: gray;">, </span>PK2<span style="color: gray;">);
</span><span style="color: blue;">insert into </span>#t <span style="color: blue;">values </span><span style="color: gray;">(</span>1<span style="color: gray;">, </span>2<span style="color: gray;">),(</span>1<span style="color: gray;">, </span>2<span style="color: gray;">);</span></pre>
<p>Now, message 2601 is not the only one complaining about duplicate keys.  Another example can be generated using the following query:</p>
<pre class="code"><span style="color: blue;">create table </span>#t <span style="color: gray;">(</span>PK1 <span style="color: blue;">int unique</span><span style="color: gray;">, </span>PK2 <span style="color: blue;">int unique</span><span style="color: gray;">);
</span><span style="color: blue;">insert into </span>#t <span style="color: blue;">values </span><span style="color: gray;">(</span>1<span style="color: gray;">, </span>2<span style="color: gray;">),(</span>1<span style="color: gray;">, </span>2<span style="color: gray;">);</span></pre>
<p>Executing that snippet on SQL Server 2008 R2 SP1 results in this error:</p>
<blockquote><p>Msg 2627, Level 14, State 1, Line 1</p>
<p>Violation of UNIQUE KEY constraint &#8216;UQ__#t________C5776555123EB7A3&#8242;. Cannot insert duplicate key in object &#8216;dbo.#t&#8217;. <strong>The duplicate key value is (2).</strong></p></blockquote>
<p>Do you notice the difference?  The message did indeed get an upgrade, but is not able to support a simultaneous violation on multiple columns, while msg 2601 can.  Hopefully they can get that fixed by SQL Server 2012 RTM!</p>
<p>Out of curiosity I decided to get a closer look at other possible variations on this error and dug into the <strong><em>sys.messages</em></strong> table using this query:</p>
<pre class="code"><span style="color: blue;">select </span><span style="color: gray;">* </span><span style="color: blue;">from </span><span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">messages
</span><span style="color: blue;">where text </span><span style="color: gray;">like (</span><span style="color: red;">'%duplicate key%'</span><span style="color: gray;">);</span></pre>
<p>Results of that query:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image429.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="All error messages containing &quot;duplicate key&quot;" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb103.png" border="0" alt="All error messages containing &quot;duplicate key&quot;" width="700" height="70" /></a></p>
<p>So, there’s one more to investigate: 1505.  To get that error generated is not that complicated.  We actually already have all the statements, just need to use them in the right order, like so:</p>
<pre class="code"><span style="color: blue;">create table </span>#t <span style="color: gray;">(</span>PK1 <span style="color: blue;">int</span><span style="color: gray;">, </span>PK2 <span style="color: blue;">int</span><span style="color: gray;">);
</span><span style="color: blue;">insert into </span>#t <span style="color: blue;">values </span><span style="color: gray;">(</span>1<span style="color: gray;">, </span>2<span style="color: gray;">),(</span>1<span style="color: gray;">, </span>2<span style="color: gray;">);
</span><span style="color: blue;">create unique index </span>PK_Unique <span style="color: blue;">on </span>#t<span style="color: gray;">(</span>PK1<span style="color: gray;">, </span>PK2<span style="color: gray;">);</span></pre>
<p>And what do we get?</p>
<blockquote><p>Msg 1505, Level 16, State 1, Line 1</p>
<p>The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name &#8216;dbo.#t__________________________________________________________________________________________________________________00000000001D&#8217; and the index name &#8216;PK_Unique&#8217;. <strong>The duplicate key value is (1, 2).</strong></p></blockquote>
<p>Nice, message 1505 also supports multiple columns, that makes two out of three!</p>
<p>Ow, don’t forget to clean up (yes, I even do that for temporary tables).</p>
<pre class="code"><span style="color: blue;">drop table </span>#t<span style="color: gray;">;</span></pre>
<h2>Additional Info</h2>
<p>Some further digging around on the internet brought me to the following suggestion on Microsoft Connect: <a title="Duplicate Key Values" href="http://connect.microsoft.com/SQLServer/feedback/details/470542/duplicate-key-values" target="_blank">Duplicate Key Values by Anton Plotnikov</a>.  Looks like our enhanced statements are the result of that request.</p>
<p>There’s another suggestion as well: <a title="Tweak To Duplicate Key Message" href="http://connect.microsoft.com/SQLServer/feedback/details/679366/tweak-to-duplicate-key-message" target="_blank">Tweak To Duplicate Key Message by Louis Davidson</a>.  Louis suggests to have all offending values added to the message as well, but in a different situation than when dealing with multiple unique columns.  You can create one insert statement that inserts more than one record with offending values, and that’s the situation he’s referring to.  If you feel that’s important, get over to Connect and cast vote!  I do think that the number of values would need to get limited in that case, we might end up with really long error messages otherwise.</p>
<p>One last link, also by Louis Davidson.  He also wrote a <a title="Denali Enhancement–Duplicate Key Error Message" href="http://sqlblog.com/blogs/louis_davidson/archive/2011/07/14/denali-enhancement-duplicate-key-error-message.aspx" target="_blank">blog post about the error message</a> when he found out about it in Denali.</p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2011%2F11%2F27%2Fenhanced-duplicate-key-error-message%2F&amp;title=Enhanced%20Duplicate%20Key%20Error%20Message" id="wpa2a_10"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2011/11/27/enhanced-duplicate-key-error-message/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSMS: Saving Changes Not Permitted</title>
		<link>http://blog.hoegaerden.be/2011/09/17/ssms-saving-changes-not-permitted/</link>
		<comments>http://blog.hoegaerden.be/2011/09/17/ssms-saving-changes-not-permitted/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 11:24:38 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Management Studio]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SSMS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2011/09/17/ssms-saving-changes-not-permitted/</guid>
		<description><![CDATA[Here’s another silly one but it catches me every time.  So I decided to write a quick post about it, to never forget about it again! Ever seen this warning message while using the Management Studio? All I did was open the AdventureWorks.Production.Product table in the designer, moved the ListPrice column above the StandardCost column [...]]]></description>
			<content:encoded><![CDATA[<p>Here’s another silly one but it catches me every time.  So I decided to write a quick post about it, to never forget about it again!</p>
<p>Ever seen this warning message while using the Management Studio?</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image424.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="Warning: Saving changes is not permitted" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb101.png" border="0" alt="Warning: Saving changes is not permitted" width="700" height="442" /></a></p>
<p>All I did was open the AdventureWorks.Production.Product table in the designer, moved the ListPrice column above the StandardCost column and hit CTRL+S to save changes.  Instead of changing the table, it tells me:</p>
<blockquote><p>Saving changes is not permitted.  The changes you have made require the following tabled to be dropped and re-created.  You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.</p></blockquote>
<p>What a message huh?!  It needs to re-create the table, so what, go ahead!  Hang on, even though this is just a Warning, there’s no Continue button!  Ow come on, are you kidding?</p>
<p>Like any good developer that wants to get some work done, you stop reading such a long message after the second line and try to find a solution for your problem.  Too bad, you should have just continued reading the warning message because the solution is actually hidden in there!</p>
<p>If you open up the <em>Options</em> screen from the <em>Tools</em> menu in SSMS, and then drill down to the <em>Designers</em> &gt; <em>Table and Database Designers </em>node, you’ll see an option called <strong>Prevent saving changes that require table re-creation</strong>.  And by default, that option is checked.  Remove the check from that box and you’ll be able to use the table designer as it was intended.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image425.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="The &quot;Prevent saving changes that require table re-creation&quot; setting" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb102.png" border="0" alt="The &quot;Prevent saving changes that require table re-creation&quot; setting" width="700" height="469" /></a></p>
<p>So, here’s your ADSOTD (Annoying Default Setting Of The Day)!</p>
<p><strong>Small note:</strong> be careful when you want to use this feature on a large table.  The script that gets generated in the background to make the changes needs to copy all records from the old table into the new one and that will obviously require some time!</p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2011%2F09%2F17%2Fssms-saving-changes-not-permitted%2F&amp;title=SSMS%3A%20Saving%20Changes%20Not%20Permitted" id="wpa2a_12"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2011/09/17/ssms-saving-changes-not-permitted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book Deal: 10 Days Of Microsoft @ Packt Publishing</title>
		<link>http://blog.hoegaerden.be/2011/09/06/book-deal-10-days-of-microsoft-packt-publishing/</link>
		<comments>http://blog.hoegaerden.be/2011/09/06/book-deal-10-days-of-microsoft-packt-publishing/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 17:33:59 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2011/09/06/book-deal-10-days-of-microsoft-packt-publishing/</guid>
		<description><![CDATA[During the whole month of September, Packt Publishing will be offering a discount on their SQL Server, SharePoint and Silverlight book collection, divided in three “10 Days Of …”. Here are the details: 10 days of SQL Server : 1st – 10th September 10 days of SharePoint :11th – 20th September 10 days of Silverlight [...]]]></description>
			<content:encoded><![CDATA[<p>During the whole month of September, Packt Publishing will be offering a discount on their SQL Server, SharePoint and Silverlight book collection, divided in three “10 Days Of …”.</p>
<p>Here are the details:</p>
<p><i><strong>10 days of SQL Server :</strong> </i>1<sup>st</sup> – 10<sup>th</sup> September</p>
<p><i><strong>10 days of SharePoint :</strong></i>11<sup>th</sup> – 20<sup>th</sup> September</p>
<p><i><strong>10 days of Silverlight : </strong></i>21<sup>st</sup> – 30<sup>th</sup> September</p>
<p>Throughout these dates there will be up to 20% off SQL Server, SharePoint and Silverlight books and 30% off eBooks – for further information visit: <a href="http://www.packtpub.com/packt-10-days-of-sql-server-silverlight-sharepoint">http://www.packtpub.com/packt-10-days-of-sql-server-silverlight-sharepoint</a></p>
<p>In case you have read my previous post, you know that there’s one book that I can surely recommend: <a title="Microsoft SQL Server 2008 R2 Master Data Services" href="http://blog.hoegaerden.be/2011/08/28/master-data-services-the-book/" target="_blank">Microsoft SQL Server 2008 R2 Master Data Services</a>!</p>
<p>As you’ve probably noticed, the first 10 days have already started, so hurry up, get yourself some reading material to get through the coming Winter (or Summer if you’re living on the Southern Hemisphere)!</p>
<p>Valentino.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2011%2F09%2F06%2Fbook-deal-10-days-of-microsoft-packt-publishing%2F&amp;title=Book%20Deal%3A%2010%20Days%20Of%20Microsoft%20%40%20Packt%20Publishing" id="wpa2a_14"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2011/09/06/book-deal-10-days-of-microsoft-packt-publishing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Master Data Services: The Book</title>
		<link>http://blog.hoegaerden.be/2011/08/28/master-data-services-the-book/</link>
		<comments>http://blog.hoegaerden.be/2011/08/28/master-data-services-the-book/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 11:30:48 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Master Data Services]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[MDS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2011/08/28/master-data-services-the-book/</guid>
		<description><![CDATA[I’ll admit it, I’ve been involved in the process of book writing!  I wasn’t the writer, no, I left that task to Jeremy Kashel, Martyn Bullerwell and Tim Kent, three guys working for a UK-based company called Adatis. I cooperated as one of the Technical Reviewers, which means I’ve read the whole book before it [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Microsoft SQL Server 2008 R2 Master Data Services" href="http://www.packtpub.com/microsoft-sql-server-2008-r2-master-data-services/book?tag=rk/r2mds-abr1/0711" target="_blank"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; float: right; padding-top: 0px; border: 0px;" title="Microsoft SQL Server 2008 R2 Master Data Services" src="http://blog.hoegaerden.be/wp-content/uploads/image423.png" border="0" alt="Microsoft SQL Server 2008 R2 Master Data Services" width="289" height="350" align="right" /></a>I’ll admit it, I’ve been involved in the process of book writing!  I wasn’t the writer, no, I left that task to <strong>Jeremy Kashel, Martyn Bullerwell and Tim Kent</strong>, three guys working for a UK-based company called Adatis.</p>
<p>I cooperated as one of the Technical Reviewers, which means I’ve read the whole book before it was published.  Obviously, just reading was not all.  I tried out all exercises to ensure that the code did not contain any mistakes and commented on possible errors, or difficult-to-understand paragraphs due to lack of details or sentences that were phrased in a weird way.</p>
<p>And I have to say, I was surprised by the quality of the text before it was even read by a Technical Reviewer.  It’s not easy to write several chapters, building further on the result of the previous one, without making any mistakes.  But the guys managed to do that just fine!</p>
<p>So, if you’re looking for a good book on <strong>Master Data Services</strong>, have a look at the <a title="Microsoft SQL Server 2008 R2 Master Data Services" href="http://www.packtpub.com/microsoft-sql-server-2008-r2-master-data-services/book?tag=rk/r2mds-abr1/0711" target="_blank">Microsoft SQL Server 2008 R2 Master Data Services</a> book, published by Packt Publishing.</p>
<p>The book is aimed at everyone new to MDS, no prior knowledge is required.  You will need to know SQL Server though, but as you’re reading my blog I’m sure that shouldn’t be a problem.</p>
<p>This doesn’t mean that it won’t go into detail though, don’t misunderstand me here.  If you’ve read the book from start to finish, you will have thorough knowledge of Master Data Services!</p>
<p>Happy reading,</p>
<p>Valentino.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2011%2F08%2F28%2Fmaster-data-services-the-book%2F&amp;title=Master%20Data%20Services%3A%20The%20Book" id="wpa2a_16"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2011/08/28/master-data-services-the-book/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Passing A DateTime Parameter Into The Execute SQL Task</title>
		<link>http://blog.hoegaerden.be/2011/06/11/passing-a-datetime-parameter-into-the-execute-sql-task/</link>
		<comments>http://blog.hoegaerden.be/2011/06/11/passing-a-datetime-parameter-into-the-execute-sql-task/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 12:31:42 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2011/06/11/passing-a-datetime-parameter-into-the-execute-sql-task/</guid>
		<description><![CDATA[When you’ve used SSIS for a while, you may have run into the following situation already.  Or maybe today is your first time and that’s the reason that you’ve arrived here. “Huh, what’s he talking about?”, I hear you thinking.  Read on then. The Scenario You’ve got a stored procedure or another SQL statement that [...]]]></description>
			<content:encoded><![CDATA[<p>When you’ve used SSIS for a while, you may have run into the following situation already.  Or maybe today is your first time and that’s the reason that you’ve arrived here.</p>
<p><em>“Huh, what’s he talking about?”,</em> I hear you thinking.  Read on then. <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>The Scenario</h2>
<p>You’ve got a stored procedure or another SQL statement that needs to get called from the <strong>Execute SQL Task</strong> in the Control Flow of your package.  So far so good.  One of the parameters that needs to get passed into the statement is of the <strong>DateTime</strong> type.</p>
<p>How would you do that?</p>
<h3>Parameter Mapping – Take 1</h3>
<p>Following the <a title="Wikipedia: KISS Principle" href="http://en.wikipedia.org/wiki/KISS_principle" target="_blank">KISS principle</a>, let’s say we’ve got the following really complex table in our database:</p>
<pre class="code"><span style="color: blue;">create table </span>dt <span style="color: gray;">( </span>dtVal <span style="color: blue;">datetime </span><span style="color: gray;">);</span></pre>
<p>And in our Execute SQL task we have this extremely complex INSERT statement:</p>
<pre class="code"><span style="color: blue;">insert into </span>dt <span style="color: blue;">values </span><span style="color: gray;">(</span>?<span style="color: gray;">)</span></pre>
<p>The statement is expecting one parameter.  The parameter that I want to pass into it is <em>System::StartTime</em> which is of type <strong>DateTime</strong> as shown in the screenshot below.</p>
<p><img style="display: inline; border-width: 0px;" title="Show the system variables by activating the Show System Variables button" src="http://blog.hoegaerden.be/wp-content/uploads/image416.png" border="0" alt="Show the system variables by activating the Show System Variables button" width="695" height="293" /></p>
<p><em>“Hang on, how did you get the Variables window to display the system variables?”</em></p>
<p>Ah, good question, by clicking that <strong>Show System Variables</strong> button, indicated with the red rectangle.</p>
<p>So you set up the <strong>Parameter Mapping</strong> as follows, specifying DBTIMESTAMP as Data Type and zero as Parameter Name because it’s the first parameter in the statement:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image417.png"><img style="display: inline; border-width: 0px;" title="Execute SQL Task: Parameter Mapping" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb100.png" border="0" alt="Execute SQL Task: Parameter Mapping" width="700" height="175" /></a></p>
<p>Then you decide to give it a test run.  But alas, it throws you the following error:</p>
<blockquote><p>Error: 0xC002F210 at Execute SQL Task 1, Execute SQL Task: Executing the query &#8220;insert into dt values (?)&#8221; failed with the following error: &#8220;Invalid time format&#8221;. Possible failure reasons: Problems with the query, &#8220;ResultSet&#8221; property not set correctly, parameters not set correctly, or connection not established correctly.</p></blockquote>
<p>So we’ve got a datetime column in the table and we’ve got a DateTime package variable.  But alas, the Execute SQL Task is not happy with passing this value to the query.</p>
<p>Now what?</p>
<h3>The SqlStatementSource Expression</h3>
<p>Let’s try another method then.  Instead of passing the parameter’s value through the Parameter Mapping page, we’ll set up an expression that constructs the whole INSERT statement, including the parameter’s value.</p>
<p>Have a look at the following expression:</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;">
<span style="color: #006080;">"insert into dt values ('"</span> +

(DT_STR, 4, 1252) DATEPART(<span style="color: #006080;">"yyyy"</span>, @[System::StartTime]) + <span style="color: #006080;">"-"</span> +

(DT_STR, 2, 1252) DATEPART(<span style="color: #006080;">"mm"</span>, @[System::StartTime]) + <span style="color: #006080;">"-"</span> +

(DT_STR, 2, 1252) DATEPART(<span style="color: #006080;">"dd"</span>, @[System::StartTime]) + <span style="color: #006080;">" "</span> +

(DT_STR, 2, 1252) DATEPART(<span style="color: #006080;">"hh"</span>, @[System::StartTime]) + <span style="color: #006080;">":"</span> +

(DT_STR, 2, 1252) DATEPART(<span style="color: #006080;">"mi"</span>, @[System::StartTime]) + <span style="color: #006080;">":"</span> +

(DT_STR, 2, 1252) DATEPART(<span style="color: #006080;">"ss"</span>, @[System::StartTime]) + <span style="color: #006080;">"."</span> +

(DT_STR, 3, 1252) DATEPART(<span style="color: #006080;">"ms"</span>, @[System::StartTime]) + <span style="color: #006080;">"')"</span></pre>
</div>
<p>It uses the DATEPART function to fetch parts of the <em>System::StartTime</em> variable and feed it into the INSERT statement using a format that works all the time (YYYY-MM-DD HH:MM:SS.MIL).  Here’s what it generated when I clicked the <strong>Evaluate Expression</strong> button in the Expression Builder:</p>
<blockquote><p>insert into dt values (&#8217;2011-5-31 17:59:37.0&#8242;)</p></blockquote>
<p>So where exactly would you specify that expression?  In the Execute SQL Task editor, open up the <em>Expressions</em> page.  Then click the Expressions item in the Misc list so that the button with the ellipsis appears.  Now click that button, select <strong>SqlStatementSource</strong> as property and click the Ellipsis button in the Expression field to get to the Expression Builder.</p>
<p>Then you’ll end up with something like this:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="The Property Expressions Editor with an expression specified for the SqlStatementSource property" src="http://blog.hoegaerden.be/wp-content/uploads/image418.png" border="0" alt="The Property Expressions Editor with an expression specified for the SqlStatementSource property" width="561" height="421" /></p>
<p>Give the package another run.  If everything has been set up as expected, the Execute SQL Task should color green and a select on the table should give one record:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="Our test table contains one timestamp!" src="http://blog.hoegaerden.be/wp-content/uploads/image419.png" border="0" alt="Our test table contains one timestamp!" width="237" height="80" /></p>
<p>Hang on, does it really have to be this complicated?</p>
<p>Well, maybe not…</p>
<h3>Parameter Mapping – Take 2</h3>
<p>So let’s give the Parameter Mapping another go.</p>
<p>Set up the Execute SQL Task just like in Take 1 above, with one small difference: select DATE instead of DBTIMESTAMP as Data Type for the parameter.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="Choose DATE as Data Type when passing a DateTime package variable into the Execute SQL Task" src="http://blog.hoegaerden.be/wp-content/uploads/image420.png" border="0" alt="Choose DATE as Data Type when passing a DateTime package variable into the Execute SQL Task" width="700" height="67" /></p>
<p>Now give the package another run.  Look at that, it colors green and there’s an extra record in the table:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="An extra timestamp was written to the table" src="http://blog.hoegaerden.be/wp-content/uploads/image421.png" border="0" alt="An extra timestamp was written to the table" width="228" height="74" /></p>
<p>DATE doesn’t seem like the most logical type to choose in this scenario, which is why most people won’t even consider it.  But it works!  Actually, “DATE” is not really the best name that could be given to this particular data type.  Here’s the description of DT_DATE (not to be confused with DT_DBDATE!) <a title="Integration Services Data Types" href="http://msdn.microsoft.com/en-us/library/ms141036.aspx" target="_blank">according to MSDN</a>:</p>
<blockquote><p>A date structure that consists of year, month, day, hour, minute, seconds, and fractional seconds. The fractional seconds have a fixed scale of 7 digits.</p>
<p>The DT_DATE data type is implemented using an 8-byte floating-point number. Days are represented by whole number increments, starting with 30 December 1899, and midnight as time zero. Hour values are expressed as the absolute value of the fractional part of the number.<strong> However, a floating point value cannot represent all real values; therefore, there are limits on the range of dates that can be presented in DT_DATE.</strong></p>
<p>On the other hand, DT_DBTIMESTAMP is represented by a structure that internally has individual fields for year, month, day, hours, minutes, seconds, and milliseconds. This data type has larger limits on ranges of the dates it can present.</p></blockquote>
<p>What this means is that you have to be careful when using this type.  Even though it works fine today, it may not run fine in a similar scenario that required different date ranges.  But obviously you’ve got that covered by your unit test scenarios!</p>
<h2>Conclusion</h2>
<p>In this article I have demonstrated how a DateTime package variable can be passed as parameter into the Execute SQL Task in more than one different way.  My method of preference is the one using the DATE type in the Parameter Mapping.</p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="SSIS Execute SQL Task" href="http://technet.microsoft.com/en-us/library/ms141003.aspx" target="_blank">SSIS Execute SQL Task</a></p>
<p><a title="DATEPART (SSIS Expression)" href="http://msdn.microsoft.com/en-us/library/ms137586.aspx" target="_blank">SSIS DatePart function</a></p>
<p><a title="Wikipedia: KISS Principle" href="http://en.wikipedia.org/wiki/KISS_principle" target="_blank">KISS Principle</a></p>
<p><a title="SSIS Junkie: Datetime variables don't always do what you expect" href="http://consultingblogs.emc.com/jamiethomson/archive/2005/03/12/SSIS_3A00_-Datetime-variables-don_2700_t-always-do-what-you-expect.aspx" target="_blank">SSIS Junkie: Datetime variables don&#8217;t always do what you expect</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2011%2F06%2F11%2Fpassing-a-datetime-parameter-into-the-execute-sql-task%2F&amp;title=Passing%20A%20DateTime%20Parameter%20Into%20The%20Execute%20SQL%20Task" id="wpa2a_18"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2011/06/11/passing-a-datetime-parameter-into-the-execute-sql-task/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Record Count For All Tables In Database</title>
		<link>http://blog.hoegaerden.be/2011/05/21/record-count-for-all-tables-in-database/</link>
		<comments>http://blog.hoegaerden.be/2011/05/21/record-count-for-all-tables-in-database/#comments</comments>
		<pubDate>Sat, 21 May 2011 08:46:33 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2011/05/21/record-count-for-all-tables-in-database/</guid>
		<description><![CDATA[In this post I’m actually just going to repeat what I answered to a question on Experts Exchange. The OP was having an issue getting a record count of all tables in his database.  It was working through the Management Studio, using the undocumented but well-known sp_MSforeachtable stored procedure. exec sp_MSforeachtable 'select ''?'' TableName, count(*) [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I’m actually just going to repeat what I answered to <a title="EE Q about getting a row count of each table in database" href="http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL_Server_2008/Q_27038565.html" target="_blank">a question on Experts Exchange</a>.</p>
<p>The OP was having an issue getting a record count of all tables in his database.  It was working through the Management Studio, using the undocumented but well-known sp_MSforeachtable stored procedure.</p>
<pre class="code"><span style="color: blue;">exec </span><span style="color: maroon;">sp_MSforeachtable </span><span style="color: red;">'select ''?'' TableName, count(*) Cnt from ?'</span><span style="color: gray;">;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>However, the OP needed the list of record counts inside an Integration Services package.  And this didn’t work out as expected, because sp_MSforeachtable uses a temporary table, something that SSIS does not like.</p>
<p>So I proposed to use a script similar to the following, possibly in a stored procedure.</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<pre class="code"><span style="color: green;">/*
DESCRIPTION: Returns a list of record counts for each table in the database
AUTHOR:         Valentino Vranken
CREATED:     2011/05/21
VERSION:     1.0
COPIED FROM: http://blog.hoegaerden.be
*/
</span><span style="color: blue;">declare </span>@tempTable <span style="color: blue;">table
</span><span style="color: gray;">(
    </span>TableSchema <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>256<span style="color: gray;">),
    </span>TableName <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>256<span style="color: gray;">),
    </span>Cnt <span style="color: blue;">bigint
</span><span style="color: gray;">);

</span><span style="color: blue;">declare </span>@sql <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>4000<span style="color: gray;">);
</span><span style="color: blue;">declare </span>@tableSchema <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>256<span style="color: gray;">);
</span><span style="color: blue;">declare </span>@tableName <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>256<span style="color: gray;">);
</span><span style="color: blue;">declare </span>@columnName <span style="color: blue;">sysname</span><span style="color: gray;">;
</span><span style="color: blue;">declare </span>@cnt <span style="color: blue;">bigint</span><span style="color: gray;">;

</span><span style="color: blue;">declare </span>tableCursor <span style="color: blue;">cursor for
    select </span>TABLE_SCHEMA<span style="color: gray;">, </span>TABLE_NAME <span style="color: blue;">from </span><span style="color: green;">INFORMATION_SCHEMA</span><span style="color: gray;">.</span><span style="color: green;">TABLES
    </span><span style="color: blue;">where </span>TABLE_TYPE <span style="color: gray;">= </span><span style="color: red;">'BASE TABLE'</span><span style="color: gray;">;

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

</span><span style="color: blue;">fetch next from </span>tableCursor <span style="color: blue;">into </span>@tableSchema<span style="color: gray;">, </span>@tableName<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
    set </span>@sql <span style="color: gray;">= </span><span style="color: red;">'select @cnt = COUNT(*) from [' </span><span style="color: gray;">+ </span>@tableSchema <span style="color: gray;">+ </span><span style="color: red;">'].[' </span><span style="color: gray;">+ </span>@tableName <span style="color: gray;">+ </span><span style="color: red;">']'</span><span style="color: gray;">;

    </span><span style="color: blue;">exec </span><span style="color: maroon;">sp_executesql </span>@sql<span style="color: gray;">, </span><span style="color: red;">N'@cnt bigint output'</span><span style="color: gray;">, </span>@cnt <span style="color: gray;">= </span>@cnt <span style="color: blue;">output</span><span style="color: gray;">;

    </span><span style="color: blue;">insert into </span>@tempTable <span style="color: blue;">select </span>@tableSchema<span style="color: gray;">, </span>@tableName<span style="color: gray;">, </span>@cnt<span style="color: gray;">;

    </span><span style="color: blue;">fetch next from </span>tableCursor <span style="color: blue;">into </span>@tableSchema<span style="color: gray;">, </span>@tableName<span style="color: gray;">;
</span><span style="color: blue;">end</span><span style="color: gray;">;

</span><span style="color: blue;">close </span>tableCursor<span style="color: gray;">;
</span><span style="color: blue;">deallocate </span>tableCursor<span style="color: gray;">;

</span><span style="color: blue;">select </span><span style="color: gray;">* </span><span style="color: blue;">from </span>@tempTable<span style="color: gray;">;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Yeah, I know, cursors are bad… But hey, at least it works!  Just don’t schedule it for execution every five seconds.</p>
<p><em>I seem to be repeating myself.  I wrote something similar when I posted <a title="Script: Find All Empty Columns In Database" href="http://blog.hoegaerden.be/2009/02/15/script-find-all-empty-columns-in-database/" target="_blank">the script about finding empty columns</a> many months ago.</em></p>
<p>The most important part of the script is the following:</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<pre class="code"><span style="color: blue;">select </span>TABLE_SCHEMA<span style="color: gray;">, </span>TABLE_NAME <span style="color: blue;">from </span><span style="color: green;">INFORMATION_SCHEMA</span><span style="color: gray;">.</span><span style="color: green;">TABLES
</span><span style="color: blue;">where </span>TABLE_TYPE <span style="color: gray;">= </span><span style="color: red;">'BASE TABLE'</span><span style="color: gray;">;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>This is using one of the information schema views to retrieve a list of tables in the database.  The INFORMATION_SCHEMA.TABLES view contains a list of tables and views, so the where clause is needed to filter out the views.  INFORMATION_SCHEMA.TABLES is just one of <a title="Information Schema Views (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms186778.aspx" target="_blank">many interesting views available in SQL Server</a>, and should always be used in favor of the sys tables.</p>
<p>What does the output look like?  Here’s part of the output when executed on the AdventureWorks2008R2 database:</p>
<p><img style="display: inline; border: 0px;" title="Record count of all tables in the AdventureWorks2008R2 database (although not all are shown, you get the idea)" src="http://blog.hoegaerden.be/wp-content/uploads/image415.png" border="0" alt="Record count of all tables in the AdventureWorks2008R2 database (although not all are shown, you get the idea)" width="376" height="183" /></p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2011%2F05%2F21%2Frecord-count-for-all-tables-in-database%2F&amp;title=Record%20Count%20For%20All%20Tables%20In%20Database" id="wpa2a_20"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2011/05/21/record-count-for-all-tables-in-database/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

