<?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>BI: Beer Intelligence? &#187; SQLServerPedia Syndication</title>
	<atom:link href="http://blog.hoegaerden.be/category/sqlserverpedia-syndication/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hoegaerden.be</link>
	<description>Serving you my best brews, one pint at a time!</description>
	<lastBuildDate>Tue, 14 May 2013 17:04:18 +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 OLE DB Source, Parameters And Comments: A Dangerous Mix!</title>
		<link>http://blog.hoegaerden.be/2012/12/05/ssis-ole-db-source-parameters-and-comments-a-dangerous-mix/</link>
		<comments>http://blog.hoegaerden.be/2012/12/05/ssis-ole-db-source-parameters-and-comments-a-dangerous-mix/#comments</comments>
		<pubDate>Wed, 05 Dec 2012 19:19:49 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQLServerPedia]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2012/12/05/ssis-ole-db-source-parameters-and-comments-a-dangerous-mix/</guid>
		<description><![CDATA[Once again I&#8217;ve been wasting some time because of a silly bug.&#160; This time it was due to the OLE DB Source component and the way it works with parameters.&#160; If you are in a situation where you know your query is working fine and yet no records are going down the data flow, here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Once again I&#8217;ve been wasting some time because of a silly bug.&#160; This time it was due to the OLE DB Source component and the way it works with parameters.&#160; If you are in a situation where you know your query is working fine and yet no records are going down the data flow, here&#8217;s a possible solution!</p>
<p><em>Disclaimer: this issue exists up until SQL Server 2008 R2.&#160; Read on for details!</em></p>
<p><em><strong><u>Update:</u> after being advised to do so by several people, including <a title="SSIS Junkie" href="http://sqlblog.com/blogs/jamie_thomson" target="_blank">Jamie Thomson</a>, I’ve filed a bug at MS Connect: </strong><a title="SSIS OLE DB Source incorrectly returns zero records in combination with parameter and comment" href="https://connect.microsoft.com/SQLServer/feedback/details/773689/ssis-ole-db-source-incorrectly-returns-zero-records-in-combination-with-parameter-and-comment" target="_blank"><strong>SSIS OLE DB Source incorrectly returns zero records in combination with parameter and comment</strong></a></em></p>
<h2>The Situation</h2>
<p>I had a Data Flow with an OLE DB Source that uses one parameter, for instance:</p>
<p>
<pre class="code"><span style="color: blue">select </span><span style="color: teal">ProductAlternateKey</span><span style="color: gray">, </span><span style="color: teal">EnglishProductName
</span><span style="color: blue">from </span><span style="color: teal">dbo</span><span style="color: gray">.</span><span style="color: teal">DimProduct
</span><span style="color: green">--some really smart comment goes here
</span><span style="color: blue">where </span><span style="color: teal">Color </span><span style="color: gray">= </span>?</pre>
</p>
<p>I knew the query was working fine because when executed through SSMS and with the question mark replaced with &#8216;blue&#8217;, it would return 28 rows:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="28 records in Management Studio" border="0" alt="28 records in Management Studio" src="http://blog.hoegaerden.be/wp-content/uploads/image554.png" width="516" height="200" /></p>
<p>But when executed in BIDS, through either Execute Package or Execute Task, it would return zero records:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="Zero records, zilch, nada, niente, none at all!" border="0" alt="Zero records, zilch, nada, niente, none at all!" src="http://blog.hoegaerden.be/wp-content/uploads/image555.png" width="152" height="154" /></p>
<p>So I thought something must be going wrong with the package variable that gets passed into the source parameter, somehow.&#160; I&#8217;m not going into details on what I tried out in my attempt to get this working, but I can tell you that I started to get really irritated.&#160; My colleague <a title="Koen Verbeeck @LessThanDot" href="http://blogs.lessthandot.com/index.php/All/?disp=authdir&amp;author=940" target="_blank">Koen Verbeeck</a> (<a title="Koen Verbeeck @LessThanDot" href="http://blogs.lessthandot.com/index.php/All/?disp=authdir&amp;author=940" target="_blank">b</a>|<a title="@Ko_Ver" href="http://twitter.com/Ko_Ver" target="_blank">t</a>) can confirm this because I called him over to my desk to help me think! (thanks btw!) <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blog.hoegaerden.be/wp-content/uploads/wlEmoticon-smile6.png" /></p>
<p>After some further tinkering with the data flow, we had our smart moment of the day and decided to launch <strong><a title="SQL Server Profiler" href="http://msdn.microsoft.com/en-us/library/ms181091.aspx" target="_blank">SQL Server Profiler</a></strong> to see what BIDS was sending to the server!&#160; I&#8217;m not sure if you&#8217;re aware of this but BIDS is doing some metadata-related stuff when preparing queries.&#160; As far as I can tell, it also tries to determine the parameter type by running the following query:</p>
<pre class="code"> <span style="color: blue">set fmtonly on select </span><span style="color: teal">Color </span><span style="color: blue">from  </span><span style="color: teal">dbo</span><span style="color: gray">.</span><span style="color: teal">DimProduct
</span><span style="color: green">--some really smart comment goes here where 1=2 set fmtonly off</span></pre>
<p>When creating this statement, it seems to use the whole FROM clause of the original query, including any trailing comments.&#160; It combines that with a SELECT statement that contains the field that gets filtered and it appends &quot;<em> where 1=2 set fmtonly off</em>&quot;.</p>
<p>But alas, apparently it&#8217;s not aware that lines can be commented out by using a double dash.&#160; So part of its generated statement is commented out.&#160; What it should have done is used some CRLFs, especially in front of the WHERE clause.&#160; But it didn&#8217;t.</p>
<p>So, as a result of that, <a title="SET FMTONLY (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms173839.aspx" target="_blank">FMTONLY</a> remains on while the SELECT statement gets executed, resulting in zero records!</p>
<p>For those unfamiliar with the FMTONLY setting: </p>
<blockquote>
<p>Returns only metadata to the client. Can be used to test the format of the response without actually running the query.</p>
</blockquote>
<p>And I can actually confirm what I’m stating here by changing the query to the following:</p>
<pre class="code"><span style="color: blue">set fmtonly off</span><span style="color: gray">;
</span><span style="color: blue">select </span><span style="color: teal">ProductAlternateKey</span><span style="color: gray">, </span><span style="color: teal">EnglishProductName
</span><span style="color: blue">from </span><span style="color: teal">dbo</span><span style="color: gray">.</span><span style="color: teal">DimProduct
</span><span style="color: green">--some really smart comment goes here
</span><span style="color: blue">where </span><span style="color: teal">Color </span><span style="color: gray">= </span>?</pre>
<p>28 records down the pipe!</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="We&#39;ve got data!" border="0" alt="We&#39;ve got data!" src="http://blog.hoegaerden.be/wp-content/uploads/image556.png" width="152" height="141" /></p>
<p>But this hack is a little too dirty to put in production.&#160; So what else can we do?&#160; Well, use block-style comments instead and we won&#8217;t face the issue!</p>
<pre class="code"><span style="color: blue">select </span><span style="color: teal">ProductAlternateKey</span><span style="color: gray">, </span><span style="color: teal">EnglishProductName
</span><span style="color: blue">from </span><span style="color: teal">dbo</span><span style="color: gray">.</span><span style="color: teal">DimProduct
</span><span style="color: green">/* some even smarter comment goes here */
</span><span style="color: blue">where </span><span style="color: teal">Color </span><span style="color: gray">= </span>?</pre>
<p>So, as I mentioned at the start of the post, this behavior can be reproduced using SSIS versions prior to 2012.&#160; What about 2012 then?&#160; Here’s the result of the Data Flow using the first query mentioned above:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="SSIS 2012: we&#39;ve got data, even with the &quot;faulty&quot; query!" border="0" alt="SSIS 2012: we&#39;ve got data, even with the &quot;faulty&quot; query!" src="http://blog.hoegaerden.be/wp-content/uploads/image557.png" width="178" height="182" /></p>
<p>Alright, that works better!&#160; Now let’s use Profiler to check what’s going on here.&#160; This is the first statement that gets executed:</p>
<pre class="code"><span style="color: blue">exec </span><span style="color: teal">[sys]</span><span style="color: gray">.</span><span style="color: teal">sp_describe_undeclared_parameters </span><span style="color: red">N'select ProductAlternateKey, EnglishProductName
from dbo.DimProduct
--some really smart comment goes here
where Color = @P1'</span></pre>
<p>Further down, I also see this one:</p>
<pre class="code"><span style="color: blue">exec </span><span style="color: teal">[sys]</span><span style="color: gray">.</span><span style="color: teal">sp_describe_first_result_set </span><span style="color: red">N'select ProductAlternateKey, EnglishProductName
from dbo.DimProduct
--some really smart comment goes here
where Color = @P1'</span><span style="color: gray">,</span><span style="color: red">N'@P1 nvarchar(15)'</span><span style="color: gray">,</span>1</pre>
<p>It is using an entirely different approach, no longer using the FMTONLY setting!&#160; Hang on, this rings a bell!&#160; Look what the <a title="MSDN: SET FMTONLY (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms173839.aspx" target="_blank">BOL page for SET FMTONLY (2012 version)</a> specifies:</p>
<blockquote>
<p>Do not use this feature. This feature has been replaced by sp_describe_first_result_set (Transact-SQL), sp_describe_undeclared_parameters (Transact-SQL), sys.dm_exec_describe_first_result_set (Transact-SQL), and sys.dm_exec_describe_first_result_set_for_object (Transact-SQL).</p>
</blockquote>
<p>Cool stuff!</p>
<h2>Conclusion</h2>
<p>If you’re not on SQL Server 2012 yet, be careful with comments in OLE DB Sources in the SSIS Data Flow!&#160; Ow, and get the SQL Server Profiler off its dusty shelf now and then!</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%2F2012%2F12%2F05%2Fssis-ole-db-source-parameters-and-comments-a-dangerous-mix%2F&amp;title=SSIS%20OLE%20DB%20Source%2C%20Parameters%20And%20Comments%3A%20A%20Dangerous%20Mix%21" 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/12/05/ssis-ole-db-source-parameters-and-comments-a-dangerous-mix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SSMS: Connect To Several Servers In One Click (Okay, Two)</title>
		<link>http://blog.hoegaerden.be/2012/11/24/ssms-connect-to-several-servers-in-one-click-okay-two/</link>
		<comments>http://blog.hoegaerden.be/2012/11/24/ssms-connect-to-several-servers-in-one-click-okay-two/#comments</comments>
		<pubDate>Sat, 24 Nov 2012 13:40:39 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Management Studio]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[SSMS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2012/11/24/ssms-connect-to-several-servers-in-one-click-okay-two/</guid>
		<description><![CDATA[I’ve been using the SQL Server Management Studio (aka SSMS) since it was first released with SQL Server 2005.&#160; And yet, it hasn’t stopped to surprise me.&#160; Earlier this week I’ve discovered a feature which I will use frequently as of now! While doing my day-time job at the customer, I have a habit of [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been using the<strong> SQL Server Management Studio</strong> (aka SSMS) since it was first released with SQL Server 2005.&#160; And yet, it hasn’t stopped to surprise me.&#160; Earlier this week I’ve discovered a feature which I will use frequently as of now!</p>
<p>While doing my day-time job at the customer, I have a habit of connecting to several servers each time when I open SSMS.&#160; I always connect to them in the same order so that I can quickly locate them in the <strong>Object Explorer</strong>.</p>
<p>The servers I want open all the time are DEV DB server, DEV SSIS server, UAT DB server and UAT SSIS server.&#160; The SSIS servers are needed to get quick access to the Job Agent, while the DB servers are what I use all the time to actually do my job.&#160; To avoid confusion: on those SSIS servers, I’m connecting to the Database Engine, not the SSIS service.</p>
<p>So, earlier this week I was trying to find a method to easily connect to these servers with as few clicks as possible.&#160; And guess what: I found one! (Well, otherwise I wouldn’t be writing this of course.)</p>
<p>In the following paragraphs I’ll describe a method which you can use to connect to several servers at once, with just two clicks!&#160; I can tell you, it sure beats the Connect To Server popup window!</p>
<p><em>Screenshots taken using SQL Server 2012, but this should work as of 2005.</em></p>
<p>First we’ll create a group of all the servers that we’d like to connect to with just two clicks.</p>
<p>Open the Management Studio and switch to the<strong> Registered Servers</strong> view.&#160; If you can’t find it, use the menu to select <em>View &gt; Registered Servers</em> or hit <em>CTRL+ALT+G</em> on your keyboard.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Open the Registered Servers view" border="0" alt="Open the Registered Servers view" src="http://blog.hoegaerden.be/wp-content/uploads/image543.png" width="401" height="154" /></p>
<p>Right-click the <em>Local Server Groups</em> node located under <em>Database Engine</em> and select <strong>New Server Group…</strong> to create a new group.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Creating a new registered servers group" border="0" alt="Creating a new registered servers group" src="http://blog.hoegaerden.be/wp-content/uploads/image544.png" width="402" height="340" /></p>
<p>Give it a good name and click OK.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="New Server Group Properties" border="0" alt="New Server Group Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image545.png" width="522" height="272" /></p>
<p>Right-click the new group and select <strong>New Server Registration…</strong>.</p>
<p>Enter the server credentials as appropriate.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="New Server Registration" border="0" alt="New Server Registration" src="http://blog.hoegaerden.be/wp-content/uploads/image546.png" width="418" height="523" /></p>
<p>What’s important here, besides the obvious such as entering correct credentials, is the <strong>Registered server name</strong>.&#160; The servers will be ordered alphabetically using that name, and<strong> that’s also the order in which they’ll be opened</strong>!&#160; So if you’re like me and you want your servers to be opened in a specific order, you’ll need some naming creativity or use numbers.&#160; In my case I’m glad that DEV orders alphabetically before UAT, which is what I want. <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blog.hoegaerden.be/wp-content/uploads/wlEmoticon-smile5.png" /></p>
<p>Ow, in case you’re wondering about that server name shown in the screenshot above, the dot refers to localhost and sql2012 is the instance name.</p>
<p>To demonstrate that I’m not joking, I’ll now register a second server and name it “Another server”.&#160; After clicking the Save button, here’s what the Registered Servers window displays:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="&quot;Another server&quot; shown above &quot;My DB Server&quot;" border="0" alt="&quot;Another server&quot; shown above &quot;My DB Server&quot;" src="http://blog.hoegaerden.be/wp-content/uploads/image547.png" width="201" height="144" /></p>
<p>As I told you, “Another server” is shown above “My DB Server” even though it was created later.</p>
<p>Now, what you’ve all been waiting for, how do I tell SSMS to connect to these servers?</p>
<p>Click number one is a<strong> right-click on the group name</strong>, My Favorite Servers in this case:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Use Object Explorer on the group name to open all servers in the group!" border="0" alt="Use Object Explorer on the group name to open all servers in the group!" src="http://blog.hoegaerden.be/wp-content/uploads/image548.png" width="467" height="187" /></p>
<p>And click number two is the one on <strong>Object Explorer</strong>!</p>
<p>SSMS will now switch to the Object Explorer window and connect to the servers, in alphabetical order!</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Object Explorer is connected to multiple servers by just two clicks!" border="0" alt="Object Explorer is connected to multiple servers by just two clicks!" src="http://blog.hoegaerden.be/wp-content/uploads/image549.png" width="348" height="351" /></p>
<p>How’s that for a time-saver huh?&#160; I hope you’ll enjoy this as much as I will!</p>
<p>As a little extra, let’s quickly discuss one more feature of the Registered Servers window.&#160; When you right-click a group, you also get a <strong>New Query</strong> menu item.&#160; Clicking that will open a query window that’s connected to all the servers in the group.&#160; You’ll be able to tell because the database dropdown in the menu reads &lt;multiple&gt;:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Query window connected to multiple servers" border="0" alt="Query window connected to multiple servers" src="http://blog.hoegaerden.be/wp-content/uploads/image550.png" width="254" height="79" /></p>
<p>And the status bar mentions the name of your server group and also &lt;multiple&gt;:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Query window connected to multiple servers" border="0" alt="Query window connected to multiple servers" src="http://blog.hoegaerden.be/wp-content/uploads/image551.png" width="611" height="42" /></p>
<p>Having a query window connected to several servers at once let’s you do interesting things, such as quickly checking what version and edition you’re running on all those servers:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Running the SELECT @@VERSION command on more than one server at once" border="0" alt="Running the SELECT @@VERSION command on more than one server at once" src="http://blog.hoegaerden.be/wp-content/uploads/image552.png" width="598" height="218" /></p>
<p>Of course, I’m sure I don’t need to remind you but I will anyway, this means it’s actually a dangerous window as well.&#160; In the database dropdown, you’ll get a list of all databases that are found on each server.&#160; There’s no advanced logic used in the process of building that list: if the database name is found on all servers in the group then the name of the DB is added to the list.</p>
<p>You can select one of those databases and execute queries against them, just like this:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Running a query against more than one database over several servers" border="0" alt="Running a query against more than one database over several servers" src="http://blog.hoegaerden.be/wp-content/uploads/image553.png" width="592" height="210" /></p>
<p>The status bar will now mention the actual database it’s connected to, which is actually its regular behavior.&#160; And the messages pane will mention how many servers you’ve run the statement against.</p>
<p>In the case above, I created a table in two tempdbs on two servers.&#160; Imagine that I ran a DROP TABLE instead, and I forgot that one of the servers in the group was the production server on which I didn’t want to drop that table.&#160; So, be careful with those windows.&#160; To avoid errors, close them as soon as you’ve finished the job for which you needed them open!</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%2F2012%2F11%2F24%2Fssms-connect-to-several-servers-in-one-click-okay-two%2F&amp;title=SSMS%3A%20Connect%20To%20Several%20Servers%20In%20One%20Click%20%28Okay%2C%20Two%29" 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/11/24/ssms-connect-to-several-servers-in-one-click-okay-two/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PASS Summit 2012: Impressions Of A First Timer</title>
		<link>http://blog.hoegaerden.be/2012/11/13/pass-summit-2012-impressions-of-a-first-timer/</link>
		<comments>http://blog.hoegaerden.be/2012/11/13/pass-summit-2012-impressions-of-a-first-timer/#comments</comments>
		<pubDate>Tue, 13 Nov 2012 18:40:40 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Community Event]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[SQLServerPedia]]></category>
		<category><![CDATA[TSQL2sday]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2012/11/13/pass-summit-2012-impressions-of-a-first-timer/</guid>
		<description><![CDATA[Even though I’m not new in the SQL Server world, last week I had the pleasure of being a First Timer at the PASS Summit in Seattle.  Many thanks to my employer Ordina for making this possible! And not only was I a First Timer at the conference, at the same time it was my [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image542.png"><img style="background-image: none; margin: 0px 0px 5px 10px; padding-left: 0px; padding-right: 0px; display: inline; float: right; padding-top: 0px; border: 0px;" title="First Timer at PASS Summit 2012" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb110.png" border="0" alt="First Timer at PASS Summit 2012" width="255" height="301" align="right" /></a>Even though I’m not new in the SQL Server world, last week I had the pleasure of being a First Timer at the <a title="PASS Summit 2012" href="http://www.sqlpass.org/summit/2012" target="_blank">PASS Summit</a> in Seattle.  Many thanks to my employer <a title="Ordina" href="http://www.ordina.be/" target="_blank">Ordina</a> for making this possible!</p>
<p>And not only was I a First Timer at the conference, at the same time it was my first trip to the US!</p>
<p>I believe I had prepared myself quite well so that I was ready to take maximum profit from all that was to be experienced in Seattle.  I attended Denny’s interesting <a title="First Timers @PASS" href="http://www.sqlpass.org/summit/2012/Connect/FirstTimers.aspx" target="_blank">First Timers</a> webcast and I read many of the <a title="First Timers blog posts" href="http://www.sqlpass.org/summit/2012/About/CommunityBlogs.aspx#First_Timers" target="_blank">First Timers blog posts</a> available through the PASS Summit site.</p>
<p>And yet, still some things took a different direction once I was actually experiencing all the great stuff at the conference.</p>
<p>Here’s a write-up of some of my encounters over there.  Not being an American I believe my post will contain some info which hasn’t been written down yet in the posts mentioned above.  On the other hand, I’d like to think it also contains good info for all first timers in the years to come, American or not.</p>
<h2>Experiencing The PASS Summit</h2>
<h3>The Jetlag Issue</h3>
<p>Never having been to America, I thought the jetlag would be okayish.  Well, it wasn’t!  In my case I arrived Monday evening and I was attending a preconference session the day after.  THIS IS NOT A GOOD IDEA!</p>
<p>Being at the conference means long days, really long days.  Breakfast starts at 7AM, the sessions start at 8AM and continue until 6PM.  And then the evening activities begin, you surely don’t want to miss out on those.</p>
<p>So, if you need to cope with a significant time difference and a long flight – in my case the trip took about 15 hours and there’s a 9-hour time difference with Belgium – leave at least one day earlier than I did so that you’ve got <strong>two nights in between arrival time and conference start</strong>.</p>
<p>Doing that also gives you a good chance to get to know the city a bit before it gets dark, and do some shopping if that’s what you’re after.  Don’t forget the gifts for the kids and wife/husband who got left alone in your home country.</p>
<p>In my case I chose to skip the two keynotes to get at least some jetlag worked away.  My reasoning was it’s better to skip the shows so that I could at least concentrate a bit more in the learning part of the conference.  Okay, some new stuff was announced but you can, in fact you WILL, always find out about that later.</p>
<p>And I was successful in getting over my jetlag, by the time it was Friday… And on Friday, I kissed Seattle goodbye to get started on yet another, even worse, jetlag! :/</p>
<h3>Getting Money</h3>
<p>If you don’t have any American dollars yet, don’t worry about exchanging money in your home country.  You can do that using <a title="Maestro" href="http://www.maestrocard.com" target="_blank">Maestro</a>.  However, give your bank a ring before getting on the plane because Maestro needs to get activated specifically for the US.  By default it is not activated because apparently 75% of fraud transactions is sourcing from the US.</p>
<p>At the same time, check with your bank if your VISA or MasterCard is activated for the US.  You may also want to increase it’s limit, depending on what that limit is currently set to and what you’re expecting to pay for with it.</p>
<p>Once you’ve arrived in the airport, use your Maestro card to get some dollars out of one of the available ATMs.  Also, insert your credit card and enter your pin code.  You don’t need to do anything with it, but entering it into the machine makes sure it’s registered as “being located in the US”.  At least, that’s what I was told to do and also what I eventually did.  I’m not sure if this step is absolutely necessary, but better be safe than don’t have any access to your credit card, right?</p>
<h3>Using Money</h3>
<p>I’m sure we all know how to use money, right?  So this chapter is mainly about the <strong>tipping</strong>, which is really different <strong>in the United States</strong> compared to Belgium (and several other European countries).</p>
<p>Here’s what I was told.  When going out to eat or drink something, you should always tip.  How much depends on the service.  The regular tipping amount is 18% and if you really liked it you should tip 20%.  If it wasn’t any good, you should still tip 15%.  That may sound weird to Europeans but apparently that’s how it works.  Well, unless they’ve been rude without cause, I guess in that case it’s okay to walk away without tipping.  Luckily I’ve only seen situations were I should tip at least 18%.</p>
<p>The last day I left my luggage with the bell boys.  A general tipping rule here is one dollar per bag, though some people give 5 dollars in total.</p>
<p>I’m not sure if the above applies to the whole of the US.  Next year the conference will be on the East Coast, Charlotte more precisely.  So if someone could let me know if tipping in Charlotte uses the same percentages as in Seattle, that would be great!</p>
<h3>Meeting People</h3>
<p>Thanks to my activity in the SQL community, which has been going on for several years now, I knew some people who were going to be present at the conference as well.  The <a title="Who’s attending the conference" href="http://www.sqlpass.org/summit/2012/Connect/WhosAttending.aspx" target="_blank">Who’s attending</a> list surely helped a lot here!</p>
<p>To make sure I didn’t forget anyone, I had made a list of names.  However, if you’re thinking that you’ll meet them by just running into them, forget about it!</p>
<p>The convention center is huge and there are more than 4000 people through which you need to search.  And as we all know, searching without an index can take a long time.  If you’re lucky then you run into them.  If you’re not, well, you don’t.  So if you really want to ensure that you’ll be able to meet someone, get their <strong>phone number</strong>!  This way you can text them to arrange a meeting location and time.  I say “text” instead of “call” here on purpose: calling abroad using my Belgian provider is really not an option unless I want to go bankrupt quickly.</p>
<p>If you didn’t get a phone number, get at least their <strong>email address</strong>.  Get linked with them on<strong> </strong><a title="LinkedIn" href="http://be.linkedin.com/in/vranken" target="_blank"><strong>LinkedIn</strong></a> and start following them on<strong> </strong><a title="Twitter" href="https://twitter.com/ValentinoV42" target="_blank"><strong>Twitter</strong></a>, prior to the conference.  Also, let them know in advance that you’ll be there as well and that you’re looking forward to meeting them!  Ow, and find out if you’re staying in the same hotel.  That can surely help to meet them during the evening hours.</p>
<p>Having done all the above will increase your chances of meeting your friends significantly.</p>
<p>Was I successful in this?  Well, partly.  I met some, I didn’t meet others.  Better luck next time!  I believe the more you’ve been there, the easier it will become.  The reason for that is that your friends have connections as well.  So the more connections you have, the higher the chances become that your connections know the ones you haven’t met yet.  In that case, they can easily introduce you!</p>
<p>So far we’ve only mentioned peers whom we’ve already been in contact with somehow before.  How about the new ones?</p>
<p>To make sure you remember who you’ve met, you should ensure that you have a stack of <strong>business cards</strong> with you.  That’s the fastest way to give someone your contact details.  Don’t try memorizing names, unless you’re really trained for that.  You’ll meet so many people in such a short amount of time that it will become really challenging.</p>
<p>If you run out of cards, note down their name on your smartphone.  Or add them on Twitter and LinkedIn.</p>
<h3>Be Smart, Get A Smartphone!</h3>
<p>No, I don’t work for a hardware reseller.  But really, if you don’t have a smartphone yet, now’s your time to get one!  If the previous paragraph didn’t make that clear yet, I’ll explain why you need one right now.</p>
<p>A lot of SQL Server professionals are active on <strong>Twitter</strong>.  And there will be free wireless internet at the convention center.  This results in a lot of Twitter activity during the whole conference period.  You’ll be able to gain a lot of additional info which you wouldn’t have without a smartphone and access to Twitter.</p>
<p>Important hash tags this year were <a title="#sqlpass" href="https://twitter.com/search?q=%23SQLPASS&amp;src=hash" target="_blank">#sqlpass</a> and <a title="#summit12" href="https://twitter.com/search?q=%23summit12&amp;src=hash" target="_blank">#summit12</a>.  Another one is <a title="#sqlfamily" href="https://twitter.com/search?q=%23sqlfamily&amp;src=hash" target="_blank">#sqlfamily</a> and you may also want to look into <a title="#sqlhelp" href="https://twitter.com/search?q=%23sqlhelp&amp;src=hash" target="_blank">#sqlhelp</a>, as explained in <a title="Why Twitter??? (For SQL People)" href="http://sarahsjolander.wordpress.com/2011/10/01/why-twitter-for-sql-people/" target="_blank">this nice article by Sarah Strate</a>.</p>
<p>In fact, Twitter is used so widely that now and then you’ll even see your friends asking where you are, through Twitter!  Don’t forget to install the Twitter app too, much easier than using a browser!</p>
<p>To give you an idea, my Twitter <strong>Followers</strong> count has increased with at least 25 in one week time!</p>
<h3>Finding A Room</h3>
<p>Don’t worry too much about this.  A convention center is used to having to deal with lots of people unfamiliar with its layout.  There are signs everywhere.  And if you’re in a rush, every entrance door is guarded by people who know their way around there so just ask them in what direction you should walk.</p>
<p>Also, if you followed my previous tip, you should have a smartphone.  This year, PASS used an app called <a title="Guidebook app" href="http://guidebook.com/" target="_blank">Guidebook</a>.  Get it installed and you have the maps (and much more) in your pocket, real easy to reach!</p>
<h3>Getting Into A Room</h3>
<p><strong>Do worry about this!</strong></p>
<p>I missed out on two good sessions (well, three actually but one of them is not a regular session) because the room was stacked with people sitting on the floor even before it started!  So if there’s a particular session that you really don’t want to miss, go there early!</p>
<p>There’s only 15 minutes in between the sessions and if you need to switch floors, take into account that 15 minutes is really, really short.  Don’t start a conversation with people you meet on your way, tell them to meet later (lunch, evening) because you don’t want to miss the session.  Don’t worry too much about hurting their feelings, they’ll probably have the same on their mind.  To avoid any misunderstanding, just tell them what you’re up to.  Who knows, if you’re lucky they’re on their way to the same room!</p>
<p>If really needed to ensure you can get into the room, leave the previous session a little early.  But only if needed and the speaker is going over the end time.</p>
<p>How do you know to which sessions you should go super early?  That’s a bit difficult to predict, but certainly don’t look at room size.  The two I missed were located in the larger rooms.  Or maybe do look at room size: if the speaker is in a larger room, that may indicate it’s a popular one!  If you know that the speaker has a popular blog, or has written popular blog: another good indicator!  And if the speaker is a regular I’m sure that’s a good indicator as well!</p>
<p>Then there are the special sessions, such as the Lightning Talks and the BI Power Hour.  I didn’t have a problem with the Lightning Session that I attended, but the Power Hour was a totally different story.  Even though it was the last session on Thursday evening, the room was packed half an hour before it even started!</p>
<h3>Travel Bags</h3>
<p>Ensure you’ve got some space left when you close up your bags at home.  You’ll be getting your hands on some swag and I’m sure you don’t want to leave part of that at the hotel because it won’t fit in your bags!</p>
<p>In my case I was travelling with a Swissgear backpack as hand luggage and a compact trolley for regular luggage.  At the conference entrance we were given a nice backpack and I didn’t want to walk around at the airport with two backpacks.  The new backpack was too large to fit in my other one so only one option remained: it had to fit in my trolley!</p>
<p>I was also lucky enough to get my hands on a free, signed copy of the <a title="Professional Microsoft SQL Server 2012 Integration Services" href="http://www.wrox.com/WileyCDA/WroxTitle/Professional-Microsoft-SQL-Server-2012-Integration-Services.productCd-111810112X,descCd-tableOfContents.html" target="_blank">Professional Microsoft SQL Server 2012 Integration Services</a> book by Brian Knight and co, which didn’t help either. <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://blog.hoegaerden.be/wp-content/uploads/wlEmoticon-smile4.png" alt="Smile" /></p>
<p>Long story short: I went home with a trolley zipper that wasn’t far from bursting and a heavy backpack because of the book!</p>
<h2>Conclusion</h2>
<p><a title="T-SQL Tuesday #36 SQL Community / What Does the Community Mean To You?" href="http://chrisyatessql.wordpress.com/2012/11/05/t-sql-tuesday-36-sql-community-what-does-the-community-mean-to-you/" target="_blank"><img style="display: inline; float: right;" title="T-SQL Tuesday" src="http://chrisyatessql.files.wordpress.com/2012/11/sql-tuesday1.jpg?w=595" alt="T-SQL Tuesday" align="right" /></a>The conference is not only about improving your SQL-fu.  It is about much more!  Meeting people you know but have never seen before, meeting new faces and minds, and of course also seeing your friends again!  Be well prepared and you’ll certainly have your hands full at the conference.</p>
<p>Coincidentally, my post seems to fit right in with <a title="T-SQL Tuesday #36 SQL Community / What Does the Community Mean To You?" href="http://chrisyatessql.wordpress.com/2012/11/05/t-sql-tuesday-36-sql-community-what-does-the-community-mean-to-you/" target="_blank">this weeks T-SQL Tuesday topic</a>, so here’s my participation!  See all of them through the <a title="#tsql2sday" href="https://twitter.com/search?q=%23tsql2sday&amp;src=hash" target="_blank">#tsql2sday</a> hashtag.</p>
<p>Looking forward to seeing my SQLFamily again!</p>
<p>And as always: remember to 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%2F2012%2F11%2F13%2Fpass-summit-2012-impressions-of-a-first-timer%2F&amp;title=PASS%20Summit%202012%3A%20Impressions%20Of%20A%20First%20Timer" 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/2012/11/13/pass-summit-2012-impressions-of-a-first-timer/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Creating Multiple-Column Reports</title>
		<link>http://blog.hoegaerden.be/2012/11/01/creating-multiple-column-reports/</link>
		<comments>http://blog.hoegaerden.be/2012/11/01/creating-multiple-column-reports/#comments</comments>
		<pubDate>Thu, 01 Nov 2012 13:11:01 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[articles]]></category>
		<category><![CDATA[SQLServerPedia]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2012/11/01/creating-multiple-column-reports/</guid>
		<description><![CDATA[Now and then I get inspired to write about a certain topic as a result of what I encounter on the forums.&#160; Here’s one of those moments. The examples in this article are created using SQL Server 2012 RTM &#8211; 11.0.2100.60 (X64).&#160; I’m also using the free AdventureWorksDW2012 sample database available at CodePlex.&#160; But that [...]]]></description>
			<content:encoded><![CDATA[<p>Now and then I get inspired to write about a certain topic as a result of what I encounter on the forums.&#160; Here’s <a title="EE: How do I specify specific number of columns in a report" href="http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27918282.html" target="_blank">one of those moments</a>.</p>
<p>The examples in this article are created using SQL Server 2012 RTM &#8211; 11.0.2100.60 (X64).&#160; I’m also using the free AdventureWorksDW2012 sample database <a href="http://msftdbprodsamples.codeplex.com/releases/view/55330" target="_blank">available at CodePlex</a>.&#160; But that doesn’t imply that you actually need 2012 to get this to work.&#160; The principle explained in this article should also work on SQL Server 2008 and even 2005.</p>
<p>You can <a title="MultiColumnReport.rdl" href="https://skydrive.live.com/embed?cid=81C8B064CBBE1698&amp;resid=81C8B064CBBE1698%21160&amp;authkey=AOsX1FAw7LHpatA" target="_blank">download the resulting RDL from my SkyDrive</a>.</p>
<h2>Introduction</h2>
<p>Have you ever needed to create a report that shows a list of something spread over multiple columns?&#160; Then you may have come across a feature called <a title="Creating Newsletter-Style Reports" href="http://technet.microsoft.com/en-us/library/ms155816(v=sql.100).aspx" target="_blank">newsletter-style reports</a>.&#160; Excited to have found out about that feature, you started creating your report.&#160; But alas, upon rendering the preview you discovered that it didn’t work.&#160; Further investigation made you conclude that the feature is only supported in two specific renderers (PDF and Image).&#160; Ouch!</p>
<p>In this article I’ll be showing you a method to create multiple-column reports that you can actually use with all renderers!</p>
<h2>Setting The Scene</h2>
<p>We’ve been asked to create a report that shows a list of product codes with each category displayed on a separate page.&#160; The codes should be displayed in four columns.</p>
<h2>Implementing The Report</h2>
<p>To get these requirements implemented, we’ll be using some T-SQL skills in combination with nested tables.&#160; So, first step is the dataset query.</p>
<h3>The Dataset</h3>
<p>The query retrieves only the fields needed in the report plus one additional, calculated field called <strong>DisplayColumn</strong>.&#160; This additional field indicates the column in which the code should get displayed.&#160; Here’s what the results look like:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="List of product codes with column number by category" border="0" alt="List of product codes with column number by category" src="http://blog.hoegaerden.be/wp-content/uploads/image523.png" width="408" height="400" /></p>
<p>As you can see, the column numbering starts at 1, goes up to 4 and then starts again at 1.&#160; It also starts at 1 again at the start of a new category.&#160; This is needed because we’ll be grouping the data on category in the report.</p>
<p>Now, let me show you that query and explain a bit how the <strong>DisplayColumn</strong> is getting calculated:</p>
<pre class="code"><span style="color: blue">declare </span><span style="color: teal">@numberOfColumns </span><span style="color: blue">int </span><span style="color: gray">= </span>4<span style="color: gray">;

</span><span style="color: blue">select </span><span style="color: teal">dpc</span><span style="color: gray">.</span><span style="color: teal">EnglishProductCategoryName</span><span style="color: gray">, </span><span style="color: teal">dp</span><span style="color: gray">.</span><span style="color: teal">ProductAlternateKey
    </span><span style="color: gray">, (</span><span style="color: magenta">ROW_NUMBER</span><span style="color: gray">() </span><span style="color: blue">OVER </span><span style="color: gray">(
        </span><span style="color: blue">PARTITION BY </span><span style="color: teal">dpc</span><span style="color: gray">.</span><span style="color: teal">EnglishProductCategoryName
        </span><span style="color: blue">ORDER BY </span><span style="color: teal">dp</span><span style="color: gray">.</span><span style="color: teal">ProductAlternateKey</span><span style="color: gray">) + </span><span style="color: teal">@numberOfColumns </span><span style="color: gray">- </span>1<span style="color: gray">) % </span><span style="color: teal">@numberOfColumns </span><span style="color: gray">+ </span>1
    <span style="color: blue">as </span><span style="color: teal">DisplayColumn
</span><span style="color: blue">from </span><span style="color: teal">dbo</span><span style="color: gray">.</span><span style="color: teal">DimProduct dp
</span><span style="color: gray">inner join </span><span style="color: teal">dbo</span><span style="color: gray">.</span><span style="color: teal">DimProductSubcategory dps </span><span style="color: blue">on </span><span style="color: teal">dps</span><span style="color: gray">.</span><span style="color: teal">ProductSubcategoryKey </span><span style="color: gray">= </span><span style="color: teal">dp</span><span style="color: gray">.</span><span style="color: teal">ProductSubcategoryKey
</span><span style="color: gray">inner join </span><span style="color: teal">dbo</span><span style="color: gray">.</span><span style="color: teal">DimProductCategory dpc </span><span style="color: blue">on </span><span style="color: teal">dpc</span><span style="color: gray">.</span><span style="color: teal">ProductCategoryKey </span><span style="color: gray">= </span><span style="color: teal">dps</span><span style="color: gray">.</span><span style="color: teal">ProductCategoryKey</span><span style="color: gray">;
</span></pre>
<p>The main ingredient here is the <a title="ROW_NUMBER() function" href="http://msdn.microsoft.com/en-us/library/ms186734.aspx" target="_blank">ROW_NUMBER</a> function.&#160; According to its definition, it “returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition”.</p>
<p>That brings us to the OVER clause, and its PARTITION BY statement.&#160; In our example we partition by category because we need the numbering to start over for each category.</p>
<p>Next up is the ORDER BY part.&#160; We order by ProductAlternateKey, which is the product code that our report should display.&#160; We want the codes to be ordered alphabetically so the column numbering should take that order into account.</p>
<p>As you can tell, I’m using some numeric trickery on the result of the ROW_NUMBER function.&#160; The reason for that is because I’d like my numbers to start at 1 and end at 4.&#160; If we would just do “row_number % 4” (% is the <a title="% - Modulo operator" href="http://msdn.microsoft.com/en-us/library/ms190279.aspx" target="_blank">modulo operator</a> btw), then our last column would be zero instead of 4.</p>
<p>Okay, that’s part one of the method explained.&#160; Over to the visualization part.</p>
<h3>Setting The Tables</h3>
<p>We’re going to create a table that shows the product category in a header with the product codes spread over four columns below the header.</p>
<p>So, first drag a table into the design canvas and give it an additional column.</p>
<p>To quickly link the table with the dataset, drag the product code field into the detail cell of the first column.</p>
<p>Now we’re going to set up the grouping.&#160; We’ll also be making use of nested tables and because tables cannot be nested on the detail level of a tablix, we need to set up grouping even on that detail level.&#160; So first, open up the <strong>Group Properties</strong> of the Details level by right-clicking it in the Row Groups pane:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Opening up the Detail-level Group Properties" border="0" alt="Opening up the Detail-level Group Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image524.png" width="279" height="154" /></p>
<p>Click the <strong>Add</strong> button to add a group and group on the product category:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Group the Detail level on product category" border="0" alt="Group the Detail level on product category" src="http://blog.hoegaerden.be/wp-content/uploads/image525.png" width="585" height="482" /></p>
<p>We want to display a header on the category level, so we’ll need to add another group on top of this one.&#160; Right-click the Details row group once more and add a <strong>Parent Group</strong>:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Adding a Parent Group to the Details level" border="0" alt="Adding a Parent Group to the Details level" src="http://blog.hoegaerden.be/wp-content/uploads/image526.png" width="467" height="151" /></p>
<p>Group by product category once more and activate the <em>Add group header</em> checkbox:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Adding parent group on product category" border="0" alt="Adding parent group on product category" src="http://blog.hoegaerden.be/wp-content/uploads/image527.png" width="367" height="192" /></p>
<p>Here’s what our table now looks like:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Some cleaning-up to be done" border="0" alt="Some cleaning-up to be done" src="http://blog.hoegaerden.be/wp-content/uploads/image528.png" width="297" height="113" /></p>
<p>We don’t need that first column and we don’t need that top row, so delete both.&#160; Now select the four textboxes in the upper row, right-click and select <strong>Merge Cells:</strong></p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Merging the header cells to prevent text getting cut off or wrapped" border="0" alt="Merging the header cells to prevent text getting cut off or wrapped" src="http://blog.hoegaerden.be/wp-content/uploads/image529.png" width="449" height="474" /></p>
<p>This way the header line gets to use all available space.&#160; Now put the product category field into the remaining merged cell and render the report:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Grouping set up as expected" border="0" alt="Grouping set up as expected" src="http://blog.hoegaerden.be/wp-content/uploads/image530.png" width="155" height="202" /></p>
<p>If all went well you should be seeing the four categories.&#160; That means the grouping part is implemented.</p>
<p>Of course, the detail level is not yet as needed because only the first code of each category is being shown and the three other columns are still empty.</p>
<p>So let’s address that now!</p>
<h3>Nesting The Tables</h3>
<p>Currently our four detail-level cells are just plain textboxes.&#160; But textboxes don’t allow filtering and we need filtering because the first column should show only the product codes with DisplayColumn equal to 1, second column 2, and so on.</p>
<p>So what we’re going to do is nest another tablix inside each of those four cells.&#160; This nested tablix should be one-celled, so just one column and one detail-level row.&#160; That can be done through several ways.&#160; I’ll show you two.</p>
<p>To set up the first detail-level cell, drag another Table inside that first textbox (the one that currently contains the product code).&#160; That gives us this:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Nesting a table in a table" border="0" alt="Nesting a table in a table" src="http://blog.hoegaerden.be/wp-content/uploads/image531.png" width="301" height="86" /></p>
<p>Now select the nested table by clicking one of its cells:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Select the nested table" border="0" alt="Select the nested table" src="http://blog.hoegaerden.be/wp-content/uploads/image532.png" width="168" height="72" /></p>
<p>It may be a bit tricky so if needed, temporarily increase the height of the detail-level row to enlarge the nested table.</p>
<p>Now remove two columns and remove the header row of the nested table.&#160; Then right-click the grey square in the upper-left corner and open up the <strong>Tablix Properties</strong>:</p>
<p><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.hoegaerden.be/wp-content/uploads/image533.png" width="208" height="176" /></p>
<p>These are the properties of the nested table.</p>
<p>Switch to the <strong>Filters</strong> page, click the Add button and set the filter to DisplayColumn = 1.</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Filter on DisplayColumn" border="0" alt="Filter on DisplayColumn" src="http://blog.hoegaerden.be/wp-content/uploads/image534.png" width="589" height="280" /></p>
<p>Click OK to close the properties.</p>
<p>Now put the product code field again in that first detail-level cell and render the report:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="One column done, three remaining!" border="0" alt="One column done, three remaining!" src="http://blog.hoegaerden.be/wp-content/uploads/image535.png" width="236" height="395" /></p>
<p>One column done, three remaining!</p>
<p>Let’s set up the second column.&#160; This time, drag a <strong>List</strong> into the second detail-level cell:</p>
<p><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.hoegaerden.be/wp-content/uploads/image536.png" width="488" height="77" /></p>
<p>A List is in fact a one-celled tablix with a Rectangle inside.&#160; But we don’t need that rectangle here, we need a Textbox.&#160; So select the rectangle by clicking once inside the cell.&#160; You can tell that the rectangle is selected by looking at the Properties window, as shown above.</p>
<p>Now hit the Delete button on the keyboard.&#160; In the Properties window, you should see Rectangle changing into Text Box:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Removing the Rectangle from the List leaves us with a Text Box" border="0" alt="Removing the Rectangle from the List leaves us with a Text Box" src="http://blog.hoegaerden.be/wp-content/uploads/image537.png" width="410" height="85" /></p>
<p>Once more we’ve got a one-celled tablix.&#160; Set up filtering on DisplayColumn = 2, using the method as explained when setting up the first column (hint: upper-left grey square).</p>
<p>Put the product code field inside the second detail-level cell and render the report:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Second column set up" border="0" alt="Second column set up" src="http://blog.hoegaerden.be/wp-content/uploads/image538.png" width="265" height="343" /></p>
<p>If all went well, your second column should now display some codes as well.</p>
<p>Two more to go!</p>
<p>Setting up the remaining two columns is actually really easy.&#160; Select the nested tablix inside the second cell by clicking the small grey square in the upper-left corner.&#160; Then hit CTRL+C, select the third detail-level cell and hit CTRL+V.&#160; Also paste into the fourth detail-level cell.</p>
<p>Now change the filtering to 3 and 4 for column three and four and render the report:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="All four columns display product codes" border="0" alt="All four columns display product codes" src="http://blog.hoegaerden.be/wp-content/uploads/image539.png" width="396" height="342" /></p>
<p>All four columns display product codes!</p>
<p>What now remains is some visual cleanup and adding page breaks on the category group.&#160; I’m only going into details on the page break.</p>
<p>In the Row Groups of the main table, right-click the upper group and select <strong>Group Properties</strong>.&#160; Then switch to the <strong>Page Breaks</strong> page and check the <em>Between each instance of a group</em> checkbox:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Adding a page break on the category group" border="0" alt="Adding a page break on the category group" src="http://blog.hoegaerden.be/wp-content/uploads/image540.png" width="585" height="482" /></p>
<p>Render the report to see the final result:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Report implemented: product codes in four columns grouped per category!" border="0" alt="Report implemented: product codes in four columns grouped per category!" src="http://blog.hoegaerden.be/wp-content/uploads/image541.png" width="382" height="334" /></p>
<p>The first page displays the product codes of the first category, spread over four columns!&#160; The other pages contain the other categories.</p>
<p>Requirements implemented!</p>
<h2>Conclusion</h2>
<p>Even though it takes a bit of work and some tricks, it is possible to create multi-column (aka newsletter-style) reports using basic SSRS components whilst still supporting all renderers.</p>
<p>I hope you enjoyed this article, have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="ROW_NUMBER()" href="http://msdn.microsoft.com/en-us/library/ms186734.aspx" target="_blank">ROW_NUMBER() function</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%2F11%2F01%2Fcreating-multiple-column-reports%2F&amp;title=Creating%20Multiple-Column%20Reports" 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/2012/11/01/creating-multiple-column-reports/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Displaying Checkboxes In An SSRS Report</title>
		<link>http://blog.hoegaerden.be/2012/08/04/displaying-checkboxes-in-an-ssrs-report/</link>
		<comments>http://blog.hoegaerden.be/2012/08/04/displaying-checkboxes-in-an-ssrs-report/#comments</comments>
		<pubDate>Sat, 04 Aug 2012 14:04:52 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2012/08/04/displaying-checkboxes-in-an-ssrs-report/</guid>
		<description><![CDATA[On the forums I now and then encounter questions asking for the possibility to display a checkbox control on a Reporting Services report.&#160; And the methods usually presented are either through images or by using a certain font one way or another.&#160; However, as of SQL Server 2008 R2 there is actually a third and [...]]]></description>
			<content:encoded><![CDATA[<p>On the forums I now and then encounter questions asking for the possibility to display a checkbox control on a Reporting Services report.&#160; And the methods usually presented are either through images or by using a certain font one way or another.&#160; However, as of SQL Server 2008 R2 there is actually a third and interesting alternative which comes really close to actually having a control!</p>
<p>In this article I&#8217;ll be presenting those three methods.</p>
<p>Screenshots are made using SSRS 2012, and so is the <a title="Checkboxes.rdl" href="https://skydrive.live.com/embed?cid=81C8B064CBBE1698&amp;resid=81C8B064CBBE1698%21152&amp;authkey=AA8htjeaq5JO0oM" target="_blank">Checkboxes.rdl available for download on my Skydrive</a>.</p>
<h2>Checkbox Control, huh?</h2>
<p>You may be wondering why people would want to put a checkbox on a report.&#160; After all, reports are not capable of accepting input &#8211; except <a title="SSRS can be also used for user inputs!" href="http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/A_8737-SSRS-can-be-also-used-for-user-inputs.html" target="_blank">through parameters</a> but that&#8217;s a different story &#8211; and isn&#8217;t that what a checkbox is all about?</p>
<p>Not entirely.&#160; Reporting Services is not only used for data exploration.&#160; Sometimes people use it to produce data-driven printouts, such as letters or even checklists.&#160; In that perspective, having checkbox control functionality would indeed be useful.</p>
<h2>A Silly Scenario</h2>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="My yummy pasta sauce" border="0" alt="My yummy pasta sauce" align="right" src="http://blog.hoegaerden.be/wp-content/uploads/image505.png" width="108" height="69" />My imagination is failing me a little today so I came up with this silly example: a recipe checklist.&#160; And today we’ll be cooking some pasta sauce!</p>
<p>This is the query that produces the list of ingredients:</p>
<pre class="code"><span style="color: blue">select </span><span style="color: red">'Yummy Pasta Sauce' </span><span style="color: blue">as </span>Recipe<span style="color: gray">, </span><span style="color: red">'zucchini' </span><span style="color: blue">as </span>Ingredient<span style="color: gray">, </span>1 <span style="color: blue">as </span>Quantity<span style="color: gray">, </span><span style="color: red">'piece' </span><span style="color: blue">as </span>Unit<span style="color: gray">, </span>1 <span style="color: blue">as </span>Needed
<span style="color: blue">union select </span><span style="color: red">'Yummy Pasta Sauce'</span><span style="color: gray">, </span><span style="color: red">'mushrooms'</span><span style="color: gray">, </span>500<span style="color: gray">, </span><span style="color: red">'g'</span><span style="color: gray">, </span>1
<span style="color: blue">union select </span><span style="color: red">'Yummy Pasta Sauce'</span><span style="color: gray">, </span><span style="color: red">'minced meat'</span><span style="color: gray">, </span>1<span style="color: gray">, </span><span style="color: red">'kg'</span><span style="color: gray">, </span>1
<span style="color: blue">union select </span><span style="color: red">'Yummy Pasta Sauce'</span><span style="color: gray">, </span><span style="color: red">'Brussels sprout'</span><span style="color: gray">, </span>1<span style="color: gray">, </span><span style="color: red">'kg'</span><span style="color: gray">, </span>0
<span style="color: blue">union select </span><span style="color: red">'Yummy Pasta Sauce'</span><span style="color: gray">, </span><span style="color: red">'onion'</span><span style="color: gray">, </span>2<span style="color: gray">, </span><span style="color: red">'piece'</span><span style="color: gray">, </span>1
<span style="color: blue">union select </span><span style="color: red">'Yummy Pasta Sauce'</span><span style="color: gray">, </span><span style="color: red">'tomato sauce'</span><span style="color: gray">, </span>1<span style="color: gray">, </span><span style="color: red">'L'</span><span style="color: gray">, </span>1
<span style="color: blue">union select </span><span style="color: red">'Yummy Pasta Sauce'</span><span style="color: gray">, </span><span style="color: red">'potato'</span><span style="color: gray">, </span>1<span style="color: gray">, </span><span style="color: red">'piece'</span><span style="color: gray">, </span>0
<span style="color: blue">union select </span><span style="color: red">'Yummy Pasta Sauce'</span><span style="color: gray">, </span><span style="color: red">'Brussels sprout'</span><span style="color: gray">, </span>1<span style="color: gray">, </span><span style="color: red">'kg'</span><span style="color: gray">, </span>0</pre>
<p>I’m cheating a bit here, all the data is hardcoded in the query.&#160; Normally you’d of course have a database that contains your recipes.</p>
<p>And I’ve also introduced some ingredients which I wouldn’t really want in my sauce, such as Brussels sprouts. Silly, but it gives me a good excuse to use the red checkbox.</p>
<p>Time to explore the possibilities.</p>
<h3>Method 1: Images</h3>
<p>I will not be going into full detail to explain the usage of images in SSRS reports.&#160; If you need additional information on that, please first read my previous article that covers all possibilities of <a title="Put Some Images On Those SSRS Reports" href="http://blog.hoegaerden.be/2010/07/07/put-some-images-on-those-ssrs-reports/" target="_blank">putting images on reports</a>.</p>
<p>As I don’t have access to an inventory of stock images, I opened my favorite drawing program, <a title="Paint.NET" href="http://www.getpaint.net/" target="_blank">Paint.NET</a>, and created two images myself.&#160; Then I embedded both images in the report:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Two images embedded in the report" border="0" alt="Two images embedded in the report" src="http://blog.hoegaerden.be/wp-content/uploads/image506.png" width="169" height="142" /></p>
<p>I created a dataset using the query above.&#160; Then I set up a Table with a group on the Recipe field whilst adding a header row to display the name of the recipe.</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="The row groups: Recipe &gt; Details" border="0" alt="The row groups: Recipe &gt; Details" src="http://blog.hoegaerden.be/wp-content/uploads/image507.png" width="151" height="75" /></p>
<p>The first column will show the ingredient details, using the following expression:</p>
<pre class="code">=Fields!Quantity.Value &amp; <span style="color: #a31515">&quot; &quot;
    </span>&amp; Fields!Unit.Value
    &amp; <span style="color: #a31515">&quot; of &quot; </span>&amp; Fields!Ingredient.Value</pre>
<p>In the second column in the detail level cell, I did a drag &amp; drop of one of my images.&#160; That gives the following pop-up:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Dragging an image into the report brings up the Image Properties" border="0" alt="Dragging an image into the report brings up the Image Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image508.png" width="585" height="532" /></p>
<p>Clicking the <em>fx</em> button brings up the brings up the Expression editor, in which I created the following expression:</p>
<div id="codeSnippetWrapper">
<pre class="code">=IIF(Fields!Needed.Value = 1, <span style="color: #a31515">&quot;checkbox_true&quot;</span>, <span style="color: #a31515">&quot;checkbox_false&quot;</span>)</pre>
</div>
<p>Rendering the report shows us:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Using images to display checkboxes on a report" border="0" alt="Using images to display checkboxes on a report" src="http://blog.hoegaerden.be/wp-content/uploads/image509.png" width="266" height="291" /></p>
<p>While easy to implement, a disadvantage to this method is that you need to get hold of the images.&#160; For my example I created them myself to avoid any copyright issues, but I wouldn’t call them fit for professional purposes.&#160; For a recipe list they serve just fine though! <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blog.hoegaerden.be/wp-content/uploads/wlEmoticon-smile3.png" /></p>
<p>Mission one accomplished: the report shows some image-based textboxes!&#160; On to mission two then!</p>
<h3>Method 2: The Wingdings Font</h3>
<p>I won’t be going into too much detail on this method either.&#160; It’s already been explained by <a title="SSRS: How to Display Checkbox on Report" href="http://kkryczka.wordpress.com/2010/12/09/how-to-display-checkbox-on-report/" target="_blank">Krzysztof Kryczka in his article here</a>.</p>
<p>In short, you just use the Wingdings font with the appropriate character to show an image.</p>
<p>In my table, I added an additional column to the right of the last one and entered the following expression:</p>
<pre class="code">=IIF(Fields!Needed.Value = 1, Chr(252), Chr(251))</pre>
<p>As you can see in the character table on Krzysztof’s site, character 252 is a check mark while 251 is a cross.&#160; Using <a title="Chr, ChrW Functions" href="http://msdn.microsoft.com/en-us/library/613dxh46(v=vs.90).aspx" target="_blank">the Chr() function</a>, I can put the character on the report without typing the letter. (I actually doubt that they even match a letter so typing it would be difficult anyway.)</p>
<p>After setting some font-related properties, here’s what the rendered report looks like:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Using the Wingdings font to show a check mark" border="0" alt="Using the Wingdings font to show a check mark" src="http://blog.hoegaerden.be/wp-content/uploads/image510.png" width="309" height="287" /></p>
<p>A small disadvantage to this method is that the Wingdings font needs to be installed on the SSRS server.</p>
<p>Mission two accomplished!&#160; On to number three!</p>
<h3>Method 3: The Indicator Control</h3>
<p>Have you already used the <a title="Indicators (Report Builder and SSRS)" href="http://technet.microsoft.com/en-us/library/ee633651.aspx" target="_blank">Indicator</a> control?&#160; It’s new since SQL Server 2008 R2!</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="The list of Report Items in the Toolbox contains an Indicator" border="0" alt="The list of Report Items in the Toolbox contains an Indicator" src="http://blog.hoegaerden.be/wp-content/uploads/image511.png" width="146" height="353" /></p>
<p>Let’s create a third column to the right of the last one and drag an Indicator into it.&#160; That brings up following pop-up:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="The SSRS Indicator comes in four different types with several different shapes!" border="0" alt="The SSRS Indicator comes in four different types with several different shapes!" src="http://blog.hoegaerden.be/wp-content/uploads/image512.png" width="572" height="482" /></p>
<p>In our context here the “3 Symbols (Uncircled)” seem like a valid option, so I’m selecting that.</p>
<p>The next step is to inform the indicator which field it should use.&#160; In our case, it’s the Needed field.&#160; It can be selected by using the dropdown next to <em>(Unspecified)</em>.</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Telling the Indicator which field is should use" border="0" alt="Telling the Indicator which field is should use" src="http://blog.hoegaerden.be/wp-content/uploads/image513.png" width="393" height="269" /></p>
<p>Let’s have a look at the rendered report now:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Using the Indicator control to display check marks!" border="0" alt="Using the Indicator control to display check marks!" src="http://blog.hoegaerden.be/wp-content/uploads/image514.png" width="358" height="284" /></p>
<p>We’ve used the built-in <strong>Indicator</strong> control to show check marks, mission three accomplished!</p>
<p><em>(remark from audience:)</em></p>
<blockquote>
<p>Erm, mister SSRS dude sir, how does the indicator know what image it should show?</p>
</blockquote>
<p><em>(me thinking:)</em></p>
<blockquote>
<p>Darn, they noticed I cheated a little.</p>
</blockquote>
<p>You’re right, I have something to confess.&#160; I made use of some handy defaults of the Indicator to skip some steps.&#160; Ready to have some fun?&#160; Add the following line to the query in the dataset:</p>
<pre class="code"><span style="color: blue">union select  </span><span style="color: red">'Yummy Pasta Sauce'</span><span style="color: gray">, </span><span style="color: red">'Let''s break it!'</span><span style="color: gray">, </span>1<span style="color: gray">, </span><span style="color: red">'attempt'</span><span style="color: gray">, </span>100</pre>
<p>Without any other changes, render the report:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Oh no, I&#39;ve broken the Indicator!" border="0" alt="Oh no, I&#39;ve broken the Indicator!" src="http://blog.hoegaerden.be/wp-content/uploads/image515.png" width="380" height="322" /></p>
<p>Oh my, look at that! The image and font-based check marks are still okay but the Indicator is broken!</p>
<p>Right, next test, in the additional query line added earlier, change the 100 to 2 and render the report:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Now the Indicator is totally broken!" border="0" alt="Now the Indicator is totally broken!" src="http://blog.hoegaerden.be/wp-content/uploads/image516.png" width="380" height="318" /></p>
<p>That surely didn’t better the situation, it made it worse!&#160; Don’t worry, the explanation is fairly easy.&#160; Let’s have a look at the actual settings of the indicator.&#160; Open the Indicator properties by right-clicking the indicator and selecting <strong>Indicator Properties</strong>.&#160; Then select the <strong>Value and States</strong> page:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="The default settings of the indicator" border="0" alt="The default settings of the indicator" src="http://blog.hoegaerden.be/wp-content/uploads/image517.png" width="585" height="530" /></p>
<p>As you can see, the units are measured using percentages with “red” starting at zero while ending at 33.&#160; That means that, based on all available values in the dataset, all values that fall in the first 33% will become red.</p>
<p>And that is exactly what the two tests above demonstrate.&#160; If we take the last one, the value ranges from zero to two.&#160; So zero is 0%, 1 is 50% and 2 is 100%.&#160; That’s why all ones end up as the yellow exclamation mark!</p>
<p>If all you need is a green/red check mark like in our example, you need to ensure that you’ve only got two possible values and the “red” value needs to be lower than the “green” value.&#160; That way you can make use of the default values of the indicator, making implementation a piece of cake.</p>
<p>Alternatively, if you’d like to customize the behavior of the indicator, that’s an option as well.&#160; Have a look at what the <em>Icon</em> dropdown produces:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="The Indicator ships with several different icons to be used" border="0" alt="The Indicator ships with several different icons to be used" src="http://blog.hoegaerden.be/wp-content/uploads/image518.png" width="198" height="318" /></p>
<p>Any of those built-in icons can be selected.&#160; Customizing the color is easy too, just use the <em>Color</em> dropdown.&#160; And of course the numeric ranges can be changed as well.</p>
<p>If the percentage-based measurement doesn’t work out well in your situation, you can switch to <em>Numeric</em>:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="The indicator can use either Percentage or Numeric measurement" border="0" alt="The indicator can use either Percentage or Numeric measurement" src="http://blog.hoegaerden.be/wp-content/uploads/image519.png" width="170" height="85" /></p>
<p>If that hasn’t convinced you yet, then I don’t know what will&#8230;</p>
<p>Alright alright, one more:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Putting smileys on your SSRS report" border="0" alt="Putting smileys on your SSRS report" src="http://blog.hoegaerden.be/wp-content/uploads/image520.png" width="386" height="289" /></p>
<h2>Conclusion</h2>
<p>In this article I’ve demonstrated three different methods of implementing checkboxes in SSRS reports.&#160; Contrary to what is currently still believed, it is actually possible to add checkboxes to a report making use of just built-in functionality!</p>
<p>Remember: have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="MSDN: Indicators" href="http://technet.microsoft.com/en-us/library/ee633651.aspx" target="_blank">MSDN: Indicators</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%2F08%2F04%2Fdisplaying-checkboxes-in-an-ssrs-report%2F&amp;title=Displaying%20Checkboxes%20In%20An%20SSRS%20Report" 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/2012/08/04/displaying-checkboxes-in-an-ssrs-report/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Counters In SSIS: What Are Your Options?</title>
		<link>http://blog.hoegaerden.be/2012/07/21/counters-in-ssis-what-are-your-options/</link>
		<comments>http://blog.hoegaerden.be/2012/07/21/counters-in-ssis-what-are-your-options/#comments</comments>
		<pubDate>Sat, 21 Jul 2012 10:35:26 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2012/07/21/counters-in-ssis-what-are-your-options/</guid>
		<description><![CDATA[The other day I needed a counter in my SSIS Control Flow.&#160; Using the Foreach Loop container I was looping over a bunch of files and needed to count the number of files that got imported successfully.&#160; The counter had to comply with the following requirements: Easy to implement Fast Let’s test some different methods [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I needed a counter in my SSIS Control Flow.&#160; Using the <a title="Foreach Loop Container" href="http://msdn.microsoft.com/en-us/library/ms141724.aspx" target="_blank">Foreach Loop container</a> I was looping over a bunch of files and needed to count the number of files that got imported successfully.&#160; The counter had to comply with the following requirements:</p>
<ul>
<li>Easy to implement </li>
<li>Fast </li>
</ul>
<p>Let’s test some different methods on getting this implemented.&#160; </p>
<h2>Counting Possibilities</h2>
<p>Two of the methods are possible as of SSIS 2005 while the third one is new since SSIS 2012. So yeah, the screenshots are taken using SQL Server 2012 RTM.</p>
<h3>Setting The Scene</h3>
<p>We’ll start from a new package and create a package variable of type Int32.&#160; This variable will keep track of the count.</p>
<p>To be able to performance test the different possibilities, I’m using a <a title="For Loop Container" href="http://msdn.microsoft.com/en-us/library/ms139956.aspx" target="_blank">For Loop container</a>.&#160; This loop is using another package variable called <em>loop</em>, type Int32, and performs the loop 10,000 times.&#160; In case you don’t know how to set up such a loop, check out this screenshot:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Using a For Loop container to test task performance" border="0" alt="Using a For Loop container to test task performance" src="http://blog.hoegaerden.be/wp-content/uploads/image491.png" width="700" height="580" /></p>
<p>So my package contains the following two variables:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Two package variables of type Int32" border="0" alt="Two package variables of type Int32" src="http://blog.hoegaerden.be/wp-content/uploads/image492.png" width="328" height="128" /></p>
<p>The <em>cnt</em> variable is the one to actually hold the count.</p>
<p>To test performance I’ll be using the command-line <a title="dtexec Utility" href="http://msdn.microsoft.com/en-us/library/hh231187.aspx" target="_blank">dtexec utility</a> so that the debugging overhead does not mess up the numbers.&#160;&#160; I’ve also executed each method at least three times to ensure a certain result was not “by accident”.</p>
<h3>Using a Script Task</h3>
<p>The most logical component that came to mind was a <a title="Script Task" href="http://msdn.microsoft.com/en-us/library/ms141752.aspx" target="_blank">Script Task</a>.</p>
<p>Using a couple lines of code, C# in this case, the counter value can be incremented with one:</p>
<pre class="code"><span style="color: blue">int </span>cnt = (<span style="color: blue">int</span>)Dts.Variables[<span style="color: #a31515">&quot;cnt&quot;</span>].Value;
Dts.Variables[<span style="color: #a31515">&quot;cnt&quot;</span>].Value = ++cnt;</pre>
<p>The above code assumes that the <em>cnt</em> variable has been put in the <strong>ReadWriteVariables</strong> property:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="The User::cnt variable is in the ReadWriteVariables for the script to use" border="0" alt="The User::cnt variable is in the ReadWriteVariables for the script to use" src="http://blog.hoegaerden.be/wp-content/uploads/image493.png" width="700" height="580" /></p>
<p>Here’s what that looks like in the Control Flow:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="For Loop container with a Script Task" border="0" alt="For Loop container with a Script Task" src="http://blog.hoegaerden.be/wp-content/uploads/image494.png" width="219" height="156" /></p>
<p>So how fast does this execute?</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image495.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Looping 10,000 times over the Script Task takes 8 seconds" border="0" alt="Looping 10,000 times over the Script Task takes 8 seconds" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb109.png" width="700" height="101" /></a></p>
<p>About eight seconds, that’s acceptable.</p>
<p>However, what I don’t like about this method is how long it takes to implement.&#160; I mean, it takes more than just a couple of seconds, right?&#160; And the fact that you actually need to use custom .NET code to perform such a trivial task as adding one to a number.&#160; Using .NET code is good for complex situations, when there’s no other option.&#160; But the risk of a bug is always larger, imagine I wrote cnt++ instead of ++cnt, what do you think the results would be? (Hint: my laptop would crash before the counter reaches 10,000).</p>
<p>On to another option then!</p>
<h3>Using a Execute SQL Task</h3>
<p>Instead of resorting to .NET code, increasing a number by one is easy to achieve using a simple T-SQL statement, right?&#160; So I thought, let’s try a <a title="Execute SQL Task" href="http://msdn.microsoft.com/en-us/library/ms141003.aspx" target="_blank">Execute SQL Task</a>!</p>
<p>Here’s the query:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">select</span> ? + 1 <span style="color: #0000ff">as</span> cnt</pre>
<p></div>
<p>What does the task look like?</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Using Execute SQL Task to increase a package variable" border="0" alt="Using Execute SQL Task to increase a package variable" src="http://blog.hoegaerden.be/wp-content/uploads/image496.png" width="700" height="580" /></p>
<p><strong>ResultSet</strong> has been set to <em>Single row</em>.</p>
<p>The<strong> Parameter Mapping</strong> page has got the <em>User::cnt</em> variable specified:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Specifying the User::cnt package variable in the Parameter Mapping page" border="0" alt="Specifying the User::cnt package variable in the Parameter Mapping page" src="http://blog.hoegaerden.be/wp-content/uploads/image497.png" width="618" height="82" /></p>
<p>And the <strong>Result Set</strong> page has got the single value from the single row mapped to the <em>User::cnt</em> package variable:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Mapping the cnt result to the User::cnt variable" border="0" alt="Mapping the cnt result to the User::cnt variable" src="http://blog.hoegaerden.be/wp-content/uploads/image498.png" width="542" height="95" /></p>
<p>What do you say, easier to implement than the Script method?&#160; I do think so!</p>
<p>This method has one limitation though: it needs a Connection Manager connecting to a SQL Server database.&#160; However, in most ETL packages you’ll probably have that present already.&#160; What I was a bit worried about though is the overhead of connecting to the server, how much will it be?</p>
<p>Let’s find out!</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="The Execute SQL Task needs almost a minute to increase the counter" border="0" alt="The Execute SQL Task needs almost a minute to increase the counter" src="http://blog.hoegaerden.be/wp-content/uploads/image499.png" width="466" height="65" /></p>
<p>That’s right, using the Execute SQL Task to increment the variable 10,000 times takes about a minute.&#160; On my laptop.&#160; Connecting to the tempdb on my local instance.&#160; When testing this over a network, it even resulted in timings over four minutes.&#160; So this solution is really unacceptable in my opinion.</p>
<p>However, we can give it one more try.&#160; A Connection Manager has got a property called <strong>RetainSameConnection</strong>.&#160; By default this is set to <em>False</em> which means that our test above has opened and closed ten thousand connections to my local tempdb.&#160; Oh my, of course that takes a while!</p>
<p>Setting it to <em>True</em> gives us the following result:</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Setting RetainSameConnection to True speeds up the process by three" border="0" alt="Setting RetainSameConnection to True speeds up the process by three" src="http://blog.hoegaerden.be/wp-content/uploads/image500.png" width="466" height="65" /></p>
<p>About twenty seconds, which is about one third of the previous result.&#160; That surely is better.&#160; And what’s perhaps even more interesting is that a similar result is achieved when connecting to a database over the network: from over four minutes down to twenty seconds.&#160; So yeah, this would work for me.</p>
<p><em><u>Sidenote</u>: for other interesting use of the RetainSameConnection property, check out </em><a title="Design Pattern: Avoiding Transactions" href="http://www.mattmasson.com/index.php/2011/12/design-pattern-avoiding-transactions/" target="_blank"><em>this post regarding transactions by Matt Masson</em></a><em>.</em></p>
<p>But we’re not stopping just yet.&#160; As of SQL Server 2012, we’ve got a third possibility!</p>
<h3>Using an Expression Task (SQL2012!)</h3>
<p>Instead of resorting to custom .NET code or (ab)using the Execute SQL Task, in SSIS 2012 we’ve got a new task: the <a title="Expression Task" href="http://msdn.microsoft.com/en-us/library/hh213137.aspx" target="_blank">Expression Task</a>.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px; padding-top: 0px" title="The new Expression Task in a For Loop Container" border="0" alt="The new Expression Task in a For Loop Container" align="right" src="http://blog.hoegaerden.be/wp-content/uploads/image504.png" width="210" height="147" /><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="The Expression Task builds and evaluates SSIS expressions, nifty!" border="0" alt="The Expression Task builds and evaluates SSIS expressions, nifty!" src="http://blog.hoegaerden.be/wp-content/uploads/image501.png" width="252" height="431" /></p>
<p>As you can read in the <a title="Where’s My SSIS Toolbox?!" href="http://blog.hoegaerden.be/2011/12/22/wheres-my-ssis-toolbox/" target="_blank">SSIS Toolbox</a>, the Expression Task builds and evaluates SSIS Expressions that set variable values at runtime.&#160; That surely sounds exactly like what we’d need, doesn’t it?</p>
<p>So how does that work?</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Using the Expression Task to increase the counter" border="0" alt="Using the Expression Task to increase the counter" src="http://blog.hoegaerden.be/wp-content/uploads/image502.png" width="700" height="634" /></p>
<p>Really easy to set up, we just specify that the<em> User::cnt</em> variable should be set to itself plus one.&#160; When put in a For Container, we’ve got a counter!</p>
<p>But how does it perform?</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="The Expression Task is the easiest and the fastest method, mission accomplished!" border="0" alt="The Expression Task is the easiest and the fastest method, mission accomplished!" src="http://blog.hoegaerden.be/wp-content/uploads/image503.png" width="460" height="67" /></p>
<p>About seven seconds, which is even slightly faster than the Script Task method!</p>
<p>With that we’ve found the method that complies with both requirements: easy to implement and performs fast!&#160; Now how am I going to convince my clients to upgrade to 2012, hmm, need to think a bit…</p>
<h2>Conclusion</h2>
<p>We found out that the new Expression Task is a very useful task for its purpose.&#160; In our case we used it to create a counter.</p>
<p>If you’re not on SQL Server 2012 yet, better stick to either Script Task or Execute SQL Task with RetainSameConnection set to True.</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%2F2012%2F07%2F21%2Fcounters-in-ssis-what-are-your-options%2F&amp;title=Counters%20In%20SSIS%3A%20What%20Are%20Your%20Options%3F" 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/2012/07/21/counters-in-ssis-what-are-your-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSIS, Flat Files And Accents (&#233;, &#232;, &#8230;)</title>
		<link>http://blog.hoegaerden.be/2012/05/03/ssis-flat-files-and-accents/</link>
		<comments>http://blog.hoegaerden.be/2012/05/03/ssis-flat-files-and-accents/#comments</comments>
		<pubDate>Thu, 03 May 2012 19:24:39 +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/2012/05/03/ssis-flat-files-and-accents/</guid>
		<description><![CDATA[This is a follow-up to my article on Loading Complex XML Using SSIS and XSLT.  In that article I demonstrated how you can convert complex XML into simple CSV using XSLT in SSIS. The resulting DTSX package and input files can be downloaded from my SkyDrive through this link. Dealing With Special Characters If you’ve [...]]]></description>
			<content:encoded><![CDATA[<p>This is a follow-up to my article on <a title="Loading Complex XML Using SSIS" href="http://blog.hoegaerden.be/2011/04/20/loading-complex-xml-using-ssis/" target="_blank">Loading Complex XML Using SSIS and XSLT</a>.  In that article I demonstrated how you can convert complex XML into simple CSV using XSLT in SSIS.</p>
<p>The resulting DTSX package and input files <a title="SSIS_FlatFiles_Accents.zip" href="https://skydrive.live.com/redir.aspx?cid=81c8b064cbbe1698&amp;resid=81C8B064CBBE1698!151&amp;parid=81C8B064CBBE1698!145" target="_blank">can be downloaded from my SkyDrive through this link</a>.</p>
<h2>Dealing With Special Characters</h2>
<p>If you’ve followed the instructions in my article mentioned above and you need to deal with special characters such as the é and è encountered in the French language, you probably noticed that it wouldn’t really work as expected.  In fact, in your final result you may have ended up with the special characters being replaced with other, even more special, characters.  Obviously not good.</p>
<p>Here’s an explanation on the reason why that happens, and also how to deal with it.</p>
<h3>Setting The Scene</h3>
<p>Imagine the following <strong>sample XML</strong>, representing a really huge book collection:</p>
<pre class="code"><span style="color: blue;">&lt;</span><span style="color: #a31515;">books</span><span style="color: blue;">&gt;
    &lt;</span><span style="color: #a31515;">book</span><span style="color: blue;">&gt;
        &lt;</span><span style="color: #a31515;">title</span><span style="color: blue;">&gt;</span>The Hitchhiker's Guide to the Galaxy<span style="color: blue;">&lt;/</span><span style="color: #a31515;">title</span><span style="color: blue;">&gt;
        &lt;</span><span style="color: #a31515;">author</span><span style="color: blue;">&gt;</span>Douglas Adams<span style="color: blue;">&lt;/</span><span style="color: #a31515;">author</span><span style="color: blue;">&gt;
        &lt;</span><span style="color: #a31515;">language</span><span style="color: blue;">&gt;</span>EN<span style="color: blue;">&lt;/</span><span style="color: #a31515;">language</span><span style="color: blue;">&gt;
        &lt;</span><span style="color: #a31515;">description</span><span style="color: blue;">&gt;</span>The Hitchhiker's Guide to the Galaxy is a science fiction comedy series created by Douglas Adams.<span style="color: blue;">&lt;/</span><span style="color: #a31515;">description</span><span style="color: blue;">&gt;
    &lt;/</span><span style="color: #a31515;">book</span><span style="color: blue;">&gt;
    &lt;</span><span style="color: #a31515;">book</span><span style="color: blue;">&gt;
        &lt;</span><span style="color: #a31515;">title</span><span style="color: blue;">&gt;</span>Le Trône de fer<span style="color: blue;">&lt;/</span><span style="color: #a31515;">title</span><span style="color: blue;">&gt;
        &lt;</span><span style="color: #a31515;">author</span><span style="color: blue;">&gt;</span>George R.R. Martin<span style="color: blue;">&lt;/</span><span style="color: #a31515;">author</span><span style="color: blue;">&gt;
        &lt;</span><span style="color: #a31515;">language</span><span style="color: blue;">&gt;</span>FR<span style="color: blue;">&lt;/</span><span style="color: #a31515;">language</span><span style="color: blue;">&gt;
        &lt;</span><span style="color: #a31515;">description</span><span style="color: blue;">&gt;</span>Le Trône de fer est une série de romans de fantasy de George R. R. Martin, dont l'écriture et la parution sont en cours. Martin a commencé à l'écrire en 1991 et le premier volume est paru en 1996. Prévue à l'origine comme une trilogie, la série compte désormais cinq volumes publiés et deux autres sont attendus.<span style="color: blue;">&lt;/</span><span style="color: #a31515;">description</span><span style="color: blue;">&gt;
    &lt;/</span><span style="color: #a31515;">book</span><span style="color: blue;">&gt;
&lt;/</span><span style="color: #a31515;">books</span><span style="color: blue;">&gt;</span></pre>
<p>As you can see, the second book in the list is the French version of the first book in the <em>A Song of Ice and Fire</em> series by George R.R. Martin and as it goes with French, there are some accents in the description of the book.</p>
<p>We’ll use the following XSLT to convert it to CSV:</p>
<pre class="code"><span style="color: blue;">&lt;?</span><span style="color: #a31515;">xml </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">1.0</span>" <span style="color: red;">encoding</span><span style="color: blue;">=</span>"<span style="color: blue;">utf-8</span>"<span style="color: blue;">?&gt;
&lt;</span><span style="color: #2b91af;">xsl:stylesheet </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">2.0</span>" <span style="color: red;">xmlns:xsl</span><span style="color: blue;">=</span>"<span style="color: blue;">http://www.w3.org/1999/XSL/Transform</span>" <span style="color: red;">xmlns:xs</span><span style="color: blue;">=</span><span style="color: blue;"><a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a></span> <span style="color: red;">xmlns:fn</span><span style="color: blue;">=</span>"<span style="color: blue;">http://www.w3.org/2005/xpath-functions</span>"<span style="color: blue;">&gt;
  &lt;</span><span style="color: #2b91af;">xsl:output </span><span style="color: red;">method</span><span style="color: blue;">=</span>"<span style="color: blue;">text</span>" <span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">1.0</span>" <span style="color: red;">encoding</span><span style="color: blue;">=</span>"<span style="color: blue;">UTF-8</span>" <span style="color: red;">indent</span><span style="color: blue;">=</span>"<span style="color: blue;">no</span>"<span style="color: blue;">/&gt;
  &lt;</span><span style="color: #2b91af;">xsl:template </span><span style="color: red;">match</span><span style="color: blue;">=</span>"<span style="color: blue;">/</span>"<span style="color: blue;">&gt;
    &lt;</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;</span>BookTitle;Author;Language;Description<span style="color: blue;">&lt;/</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;
    &lt;</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;</span><span style="color: red;">&amp;#13;&amp;#10;</span><span style="color: blue;">&lt;/</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;

    &lt;</span><span style="color: #2b91af;">xsl:for-each </span><span style="color: red;">select</span><span style="color: blue;">=</span>"<span style="color: blue;">books/book</span>"<span style="color: blue;">&gt;
      &lt;</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;</span>"<span style="color: blue;">&lt;/</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;
      &lt;</span><span style="color: #2b91af;">xsl:value-of </span><span style="color: red;">select</span><span style="color: blue;">=</span>"<span style="color: blue;">title</span>"<span style="color: blue;">/&gt;
      &lt;</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;</span>";"<span style="color: blue;">&lt;/</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;
      &lt;</span><span style="color: #2b91af;">xsl:value-of </span><span style="color: red;">select</span><span style="color: blue;">=</span>"<span style="color: blue;">author</span>"<span style="color: blue;">/&gt;
      &lt;</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;</span>";"<span style="color: blue;">&lt;/</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;
      &lt;</span><span style="color: #2b91af;">xsl:value-of </span><span style="color: red;">select</span><span style="color: blue;">=</span>"<span style="color: blue;">language</span>"<span style="color: blue;">/&gt;
      &lt;</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;</span>";"<span style="color: blue;">&lt;/</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;
      &lt;</span><span style="color: #2b91af;">xsl:value-of </span><span style="color: red;">select</span><span style="color: blue;">=</span>"<span style="color: blue;">description</span>"<span style="color: blue;">/&gt;
      &lt;</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;</span>"<span style="color: blue;">&lt;/</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;
      &lt;</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;</span><span style="color: red;">&amp;#13;&amp;#10;</span><span style="color: blue;">&lt;/</span><span style="color: #2b91af;">xsl:text</span><span style="color: blue;">&gt;
    &lt;/</span><span style="color: #2b91af;">xsl:for-each</span><span style="color: blue;">&gt;

  &lt;/</span><span style="color: #2b91af;">xsl:template</span><span style="color: blue;">&gt;
&lt;/</span><span style="color: #2b91af;">xsl:stylesheet</span><span style="color: blue;">&gt;</span></pre>
<p>Using an <strong>XML Task </strong>in the Control Flow, as explained in my article, we’d get the following output:</p>
<p><span style="font-family: Courier New;">BookTitle;Author;Language;Description</span><br />
<span style="font-family: Courier New;">&#8220;The Hitchhiker&#8217;s Guide to the Galaxy&#8221;;&#8221;Douglas Adams&#8221;;&#8221;EN&#8221;;&#8221;The Hitchhiker&#8217;s Guide to the Galaxy is a science fiction comedy series created by Douglas Adams.&#8221;</span><br />
<span style="font-family: 'Courier New';">&#8220;Le Trône de fer&#8221;;&#8221;George R.R. Martin&#8221;;&#8221;FR&#8221;;&#8221;Le Trône de fer (A Song of Ice and Fire) est une série de romans de fantasy de George R. R. Martin, dont l&#8217;écriture et la parution sont en cours. Martin a commencé à l&#8217;écrire en 1991 et le premier volume est paru en 1996. Prévue à l&#8217;origine comme une trilogie, la série compte désormais cinq volumes publiés et deux autres sont attendus.&#8221;</span></p>
<p><span style="font-family: 'Courier New';"> </span></p>
<p><span style="font-family: 'Courier New';"> </span></p>
<p>So far so good, all accents are still present!</p>
<p>Then we’d import the file using a <strong>Flat File Source</strong> component in a Data Flow Task.  Here’s what the General page of the Flat File Connection Manager would look like:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Flat File Connection Manager: General" src="http://blog.hoegaerden.be/wp-content/uploads/image469.png" border="0" alt="Flat File Connection Manager: General" width="704" height="637" /></p>
<p>We’ve set double-quote as <strong>Text Qualifier</strong> and checked the <strong>Column names in the first data row</strong> textbox.</p>
<p>Switching to the Columns page we’d get the following:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Flat File Connection Manager: Columns - the Preview has messed up the accents!" src="http://blog.hoegaerden.be/wp-content/uploads/image470.png" border="0" alt="Flat File Connection Manager: Columns - the Preview has messed up the accents!" width="700" height="548" /></p>
<p>Hang on, that’s not right!  The Preview is not displaying our accents as expected!  Oh my, what’s going on here? Let’s call the code page detectives!</p>
<h3>A Mismatch Investigation</h3>
<p>Take a good look at the XSLT which we’ve used to convert the XML into CSV, especially the <strong>xsl:output</strong> line:</p>
<p><span style="color: blue;">&lt;</span><span style="color: #2b91af;">xsl:output </span><span style="color: red;">method</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">text</span>&#8221; <span style="color: red;">version</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">1.0</span>&#8221; <span style="color: red;">encoding</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">UTF-8</span>&#8221; <span style="color: red;">indent</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">no</span>&#8220;<span style="color: blue;">/&gt;</span></p>
<p>That line specifies that the text output should be encoded using the <a title="Wikipedia: UTF-8" href="http://en.wikipedia.org/wiki/UTF-8" target="_blank">UTF-8 code page</a>.</p>
<p>Now take a good look at the General page in the screenshot earlier, more precisely this part:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Code page: 1252 (ANSI - Latin I) is not what we need right now!" src="http://blog.hoegaerden.be/wp-content/uploads/image471.png" border="0" alt="Code page: 1252 (ANSI - Latin I) is not what we need right now!" width="627" height="34" /></p>
<p>Indeed, code page 1252 (ANSI – Latin I).  While the input is UTF-8.  Of course that results in a mismatch of certain characters, as demonstrated here.  The fix is fairly easy, just change the <strong>Code page</strong> setting to <strong>65001 (UTF-8).</strong></p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Code page: 65001 (UTF-8) - much better!" src="http://blog.hoegaerden.be/wp-content/uploads/image472.png" border="0" alt="Code page: 65001 (UTF-8) - much better!" width="633" height="35" /></p>
<p>If we now switch back to the Columns page we should come to the following result:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Flat File Connection Manager: Columns page preview with accents!" src="http://blog.hoegaerden.be/wp-content/uploads/image473.png" border="0" alt="Flat File Connection Manager: Columns page preview with accents!" width="700" height="548" /></p>
<p>Ah, sure looks better doesn’t it?  All accents are present as expected.</p>
<p>But in case you thought that’s it, I’d advise you to think again.  Don’t worry, I’ll demonstrate what I mean.  Let’s do that by setting up a simple Data Flow.</p>
<h3>Setting Up The Data Flow</h3>
<p>Throw in a<strong> Flat File Source</strong> and specify our Flat File Connection Manager.  I also prefer to keep NULLs as they come in, using the <strong>Retain null values from the source as null values in the data flow</strong> checkbox.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Flat File Source: Connection Manager" src="http://blog.hoegaerden.be/wp-content/uploads/image474.png" border="0" alt="Flat File Source: Connection Manager" width="700" height="607" /></p>
<p>If you click the Preview button you should get similar output as shown one screenshot earlier.</p>
<p>Now hook this up to an <strong>OLE DB Destination </strong>that writes the incoming data into a table in your favorite database:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="OLE DB Destination is not happy :(" src="http://blog.hoegaerden.be/wp-content/uploads/image475.png" border="0" alt="OLE DB Destination is not happy :(" width="151" height="142" /></p>
<p>As you can see, our destination is not entirely happy with all this.  Here are the details of one of the error messages:</p>
<blockquote><p>Validation error. Data Flow Task: Data Flow Task: The column &#8220;BookTitle&#8221; cannot be processed because more than one code page (65001 and 1252) are specified for it.</p></blockquote>
<p>Looks like once more we’ve got a code page conflict.  And we sure do. Clicking the Data Flow connector between the Flat File source and OLE DB destination shows us the following:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Data Flow Path Editor shows that our strings are encoded using the 65001 code page." src="http://blog.hoegaerden.be/wp-content/uploads/image476.png" border="0" alt="Data Flow Path Editor shows that our strings are encoded using the 65001 code page." width="700" height="461" /></p>
<p>Each of our incoming string values is encoded using the 65001 (UTF-8) code page.  But our database was created using the Latin1_General_CI_AS collation.  So we’ve indeed got a code page conflict!</p>
<p>Fear not, that’s easily remedied.  Add a <strong>Derived Column</strong> transformation in between the source and destination and convert each incoming string value using a cast expression such as this one:</p>
<p><span style="font-family: Courier New;">(DT_STR, 50, 1252)BookTitle_IN</span></p>
<p><strong><span style="text-decoration: underline;">Note:</span></strong> whenever I need to manipulate incoming columns to create a second version of the same column, I rename the incoming column to <em>TheColumn_IN</em>.  The new version will be called <em>TheColumn</em> and preferably <em>TheColumn</em> is the name of the field in the destination table.  This makes it easy to distinguish all columns later down the flow.</p>
<p>Here’s what the final version of the Derived Column looks like:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image477.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Using the Derived Column transformation to cast the incoming strings into the correct code page." src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb107.png" border="0" alt="Using the Derived Column transformation to cast the incoming strings into the correct code page." width="700" height="559" /></a></p>
<p>Next we’ll need to open the Destination and change the mapped fields to the new ones.  Because my new columns are called exactly the same as the fields in the destination table, I can do that easily.  In the <strong>Mappings</strong> page, all I need to do is right-click the grey background in between the two tables and click <strong>Select All Mappings</strong>, hit the Delete button, right-click again and click <strong>Map Items By Matching Names:</strong></p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Using Map Items By Matching Names, easy!" src="http://blog.hoegaerden.be/wp-content/uploads/image478.png" border="0" alt="Using Map Items By Matching Names, easy!" width="700" height="441" /></p>
<p>With the data flow finished, let’s give our package a run!</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Flat File Source has got a length issue!" src="http://blog.hoegaerden.be/wp-content/uploads/image479.png" border="0" alt="Flat File Source has got a length issue!" width="154" height="213" /></p>
<p>Ouch, our source is not happy!  A closer examination of the Output pane brings us to the following error:</p>
<blockquote><p>Error: 0xC02020A1 at Data Flow Task, Flat File Source [16]: Data conversion failed. The data conversion for column &#8220;Description&#8221; returned status value 4 and status text &#8220;Text was truncated or one or more characters had no match in the target code page.&#8221;.</p></blockquote>
<p>Oh right, so far we haven’t bothered looking at the actual length of the data that we’re importing.  Actually, what is the length of our data flow columns??  Well, if you’ve been paying close attention you should have noticed the number 50 several times in the screenshots and expressions above.  That’s indeed the default length for text columns when importing a flat file.</p>
<p>And if you scroll back up to the sample XML, you’ll notice that the content for the description is longer than 50 characters, thus causing our error!  Let’s find out how to get that solved!</p>
<h3>Fixing The Field Length Issue</h3>
<p>The first step in getting this fixed is opening up the Advanced page in the Flat File Connection Manager editor.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Flat File Connection Manager: using the Advanced page to change field length." src="http://blog.hoegaerden.be/wp-content/uploads/image480.png" border="0" alt="Flat File Connection Manager: using the Advanced page to change field length." width="700" height="633" /></p>
<p>Then select the Description field and change its <strong>OutputColumnWidth</strong> property from 50 to 500.</p>
<p>That will cause the source to generate a warning.  Remove this warning by opening and closing the source editor.  Click the Yes button in the popup that appears.</p>
<p>The next step is changing the expression for the Description field in the Derived Column to this:</p>
<p><span style="font-family: Courier New;">(DT_STR,500,1252)Description_IN</span></p>
<p>Indeed, the field length is one of the parameters in that cast.  The other numeric parameter is obviously the code page.</p>
<p>Having done that you’ll notice that the destination will start complaining.  Of course, you’ll need to adapt the destination table to reflect the field length increase as well.  So change the table definition and open/close the destination editor to make it happy.</p>
<p>Alright, let’s run the package once more!</p>
<p>Finally the data flow is happy with it all and has inserted two records:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="That's more like it: all components colored green!" src="http://blog.hoegaerden.be/wp-content/uploads/image481.png" border="0" alt="That's more like it: all components colored green!" width="150" height="218" /></p>
<p>And what does our table contain?  Let’s find out:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image482.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="All accents have been imported!" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb108.png" border="0" alt="All accents have been imported!" width="700" height="65" /></a></p>
<p>That’s looking good for sure!</p>
<h2>Conclusion</h2>
<p>In this follow-up article I have demonstrated what might go wrong when you need to deal with special characters while importing flat files, and how to solve your possible issues.  In case you missed the original article, <a title="Loading Complex XML Using SSIS" href="http://blog.hoegaerden.be/2011/04/20/loading-complex-xml-using-ssis/" target="_blank">have a look through this link</a>.</p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="Wikipedia: UTF-8" href="http://en.wikipedia.org/wiki/UTF-8" target="_blank">Wikipedia: UTF-8</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%2F05%2F03%2Fssis-flat-files-and-accents%2F&amp;title=SSIS%2C%20Flat%20Files%20And%20Accents%20%28%C3%A9%2C%20%C3%A8%2C%20%E2%80%A6%29" 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/2012/05/03/ssis-flat-files-and-accents/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>SQL Server Data Tools (SSDT)</title>
		<link>http://blog.hoegaerden.be/2012/04/18/sql-server-data-tools-ssdt/</link>
		<comments>http://blog.hoegaerden.be/2012/04/18/sql-server-data-tools-ssdt/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 15:27:18 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server Data Tools]]></category>
		<category><![CDATA[SSDT]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2012/04/18/sql-server-data-tools-ssdt/</guid>
		<description><![CDATA[You may or may not already have heard about it, but the next version of our favorite database, SQL Server 2012, ships with a client tool called SQL Server Data Tools (SSDT).  Just like the BIDS was actually Visual Studio 2008 (or 2005 if you’re long enough in the business) with BI-related project templates, SSDT [...]]]></description>
			<content:encoded><![CDATA[<p>You may or may not already have heard about it, but the next version of our favorite database, SQL Server 2012, ships with a client tool called <strong>SQL Server Data Tools </strong>(SSDT).  Just like the BIDS was actually Visual Studio 2008 (or 2005 if you’re long enough in the business) with BI-related project templates, SSDT is Visual Studio 2010.  But that’s not all: it contains additional functionality!  Do you remember the database projects you could create using the “data dude”, or officially known as Visual Studio 2008 with the GDR2 add-on?  Well, this is version-next of the data dude.</p>
<p>Let’s find out how such a database project can be created!</p>
<h2>Getting Started With SSDT</h2>
<p>Obviously the first step is installing SQL Server 2012 and making sure to select <em>SQL Server Data Tools</em> in the <strong>Feature Selection</strong> page:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="SQL Server 2012 Feature Selection with the SQL Server Data Tools checked" src="http://blog.hoegaerden.be/wp-content/uploads/SQL2012EVAL_FeatureSelection.png" border="0" alt="SQL Server 2012 Feature Selection with the SQL Server Data Tools checked" width="700" height="525" /></p>
<p>With that up and running, launch the SQL Server Data Tools from the Microsoft SQL Server 2012 folder in the Start menu and go to File &gt; New Project.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="New Project - SQL Server Data Tools" src="http://blog.hoegaerden.be/wp-content/uploads/005_NewProject.png" border="0" alt="New Project - SQL Server Data Tools" width="700" height="484" /></p>
<p>One of the template categories is called SQL Server.  Under that you’ll find a template called <strong>SQL Server Data Tools – Database Projects (Web Install)</strong>.</p>
<p>Erm, hang on, what do you mean, “web install”?  Does that mean it’s not installed yet?  The description on the right also gives some clue to what’s going on: “provides instructions for installing SQL Server Data Tools – Database Projects from the web”.  Okay, let’s get on with it then!</p>
<p>Click the OK button to proceed to the installer.</p>
<h3>Installing the SSDT Database Projects template</h3>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="SQL Server Data Tools - Database Projects (Web Install)" src="http://blog.hoegaerden.be/wp-content/uploads/010_InstallSSDT.png" border="0" alt="SQL Server Data Tools - Database Projects (Web Install)" width="467" height="250" /></p>
<p>I think the message in that window above is a bit misleading.  It says that “Database Projects” is required, but isn’t that what we’re going to install now?  Sounds like chicken and egg to me!  Let’s just ignore the message then and click the Install button.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Data Developer Center - Download SQL Server Data Tools" src="http://blog.hoegaerden.be/wp-content/uploads/011_DataDeveloperCenter_DownloadSSDT.png" border="0" alt="Data Developer Center - Download SQL Server Data Tools" width="700" height="521" /></p>
<p>We’re now presented with a web page in Internet Explorer.  In this Data Developer Center, click the blue Download SQL Server Data Tools link.</p>
<p>Next, when presented with the following pop-up, click Allow:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Do you want to allow this website to open a program on your computer? Yes we do!" src="http://blog.hoegaerden.be/wp-content/uploads/012_AllowCancel.png" border="0" alt="Do you want to allow this website to open a program on your computer? Yes we do!" width="411" height="296" /></p>
<p>The next window is the Web Platform Installer 3.0 that wants to install the Microsoft SQL Server Data Tools.  Click the Install button to get to the next step.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Web Platform Installer 3.0 - 1 items to be installed" src="http://blog.hoegaerden.be/wp-content/uploads/025_WebPlatformInstaller.png" border="0" alt="Web Platform Installer 3.0 - 1 items to be installed" width="700" height="485" /></p>
<p>As usual with any installer from Microsoft, we need to accept the license terms so click the Accept button.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Web Platform Installation - Accept License Terms" src="http://blog.hoegaerden.be/wp-content/uploads/030_DeclineAccept.png" border="0" alt="Web Platform Installation - Accept License Terms" width="700" height="480" /></p>
<p>Finally, the installation begins!</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Web Platform Installation - Progress Bar" src="http://blog.hoegaerden.be/wp-content/uploads/035_ProgressBar.png" border="0" alt="Web Platform Installation - Progress Bar" width="700" height="480" /></p>
<p>To keep us busy, we’re presented with another pop-up with a progress bar:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.hoegaerden.be/wp-content/uploads/image466.png" border="0" alt="image" width="700" height="379" /></p>
<p>Woah!  Is this thing installing <a title="SQL Server 2012 Express LocalDB" href="http://msdn.microsoft.com/en-us/library/hh510202.aspx" target="_blank">SQL Server 2012 Express LocalDB</a> like it says in the message?  I didn’t ask for that!  MS people, as I already have a version 2012 DB engine running on my machine, please make this optional…</p>
<p>Just a little later we’re presented with this:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Web Platform Installation - Congratulations!" src="http://blog.hoegaerden.be/wp-content/uploads/050_Finish.png" border="0" alt="Web Platform Installation - Congratulations!" width="700" height="480" /></p>
<p>Clicking the Finish button gives us yet one more pop-up:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Web Platform Installer 3.0 - Spotlight" src="http://blog.hoegaerden.be/wp-content/uploads/055_WebPlatformInstaller3.png" border="0" alt="Web Platform Installer 3.0 - Spotlight" width="700" height="485" /></p>
<p>The Web Platform Installer presents us with a list of applications we can install, including Microsoft SQL Server Data Tools.  Oh my, I thought we just finished installing it?  Let’s not be silly and click the Exit button</p>
<p>To conclude, we need to restart Visual Studio 2010, or aka SSDT.</p>
<h2>Really Getting Started With SSDT</h2>
<p>With everything up and running smoothly this time, open SSDT once more and in File &gt; New Project you’ll now find the <strong>SQL Server Database Project</strong> under the SQL Server collection:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="New Project - SQL Server Database Project" src="http://blog.hoegaerden.be/wp-content/uploads/image467.png" border="0" alt="New Project - SQL Server Database Project" width="700" height="392" /></p>
<p>If you also have Visual Studio 2010 installed in <a title="Visual Studio 2010: Feature Comparison" href="http://www.microsoft.com/visualstudio/en-gb/products" target="_blank">Premium or Ultimate edition</a>, you should take care to open up the correct SQL Server template collection.  The reason for that is because the data dude projects are included in those versions of Visual Studio, as shown in the screenshot below:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The SQL Server templates in Visual Studio 2010" src="http://blog.hoegaerden.be/wp-content/uploads/VS2010_NewDBProject.png" border="0" alt="The SQL Server templates in Visual Studio 2010" width="700" height="484" /></p>
<p>So the templates under Database &gt; SQL Server are <strong>not</strong> what you’re looking for!</p>
<p>That’s it for now, I’ll demonstrate my favorite SSDT feature in an upcoming post!</p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="Microsoft SQL Server Data Tools" href="http://msdn.microsoft.com/en-us/data/gg427686" target="_blank">SSDT Main page on Data Developer Center</a></p>
<p><a title="SQL Server Data Tools Team Blog" href="http://blogs.msdn.com/b/ssdt/" target="_blank">SQL Server Data Tools Team Blog</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%2F04%2F18%2Fsql-server-data-tools-ssdt%2F&amp;title=SQL%20Server%20Data%20Tools%20%28SSDT%29" 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/2012/04/18/sql-server-data-tools-ssdt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building Reports With Dynamic Datasets</title>
		<link>http://blog.hoegaerden.be/2012/03/20/building-reports-with-dynamic-datasets/</link>
		<comments>http://blog.hoegaerden.be/2012/03/20/building-reports-with-dynamic-datasets/#comments</comments>
		<pubDate>Tue, 20 Mar 2012 19:35:37 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2012/03/20/building-reports-with-dynamic-datasets/</guid>
		<description><![CDATA[On the forums I regularly encounter questions like: I have a report and want to show A, B, C but sometimes I want X, Y, Z and not A, B, C. How? Or, in other words: I have a parameter and based on the selection I want to return different fields in my dataset.  How [...]]]></description>
			<content:encoded><![CDATA[<p>On the forums I regularly encounter questions like:</p>
<blockquote><p>I have a report and want to show A, B, C but sometimes I want X, Y, Z and not A, B, C. How?</p></blockquote>
<p>Or, in other words:</p>
<blockquote><p>I have a parameter and based on the selection I want to return different fields in my dataset.  How can I do that?</p></blockquote>
<p>My initial reaction would be “I don’t think you can do that”.  But then I thought it would be useful in certain situations and decided to try it out. And guess what?  You can do that!  Here’s how.</p>
<p>Just to make sure everyone is on track: this article is not about dynamicity in terms of rows returned, that would be <a title="How to: Add a Filter to a Dataset (Report Builder 3.0 and SSRS)" href="http://technet.microsoft.com/en-us/library/dd255287.aspx" target="_blank">filtered datasets</a> and you’ll already find plenty of <a title="Working with Reporting Services Filters–Part 1" href="http://blog.datainspirations.com/2010/12/21/working-with-reporting-services-filterspart-1/" target="_blank">references</a> on the internet.  This article is about a varying number of columns in the dataset, which is a little less straightforward.</p>
<p>The database used in the examples is AdventureWorks2008R2, <a title="Sample Database" href="http://msftdbprodsamples.codeplex.com/" target="_blank">available at Codeplex</a>.  And the screenshots are taken from SQL Server 2008 R2 x64 SP1.</p>
<h2>The Scenario</h2>
<p>The report we’re going to build should show a list of products sold.  But the report is used by different user groups: those who just want to see the sales numbers and those who also care about stock levels!</p>
<p>So by default the report should show a list of items and number sold, but it should also be possible to render that same report whilst displaying the stock-related statistics.</p>
<p>And to make it even a bit more interesting, by default the data should be ordered according to product number but in “stock level mode” the ordering should put those with the lowest current stock first.</p>
<h2>The Report</h2>
<p>Let’s get started!  The first step in creating a report is often the writing of a SELECT statement.  In this scenario we’ll be needing two of them, both in the same dataset.</p>
<h3>The Dataset</h3>
<p>Our dataset is going to need a parameter to be able to decide what type of user is requesting the report. Let’s call that parameter <em>WithStockData</em>, and its <strong>type</strong> will be <em>Boolean</em>.</p>
<p>The layout of the dataset statement will be this:</p>
<pre class="code"><span style="color: blue;">if </span>@WithStockData <span style="color: gray;">= </span>1
<span style="color: green;">-- sales and stock data
</span><span style="color: blue;">else
</span><span style="color: green;">-- regular sales data</span></pre>
<p>A simple <a title="IF...ELSE (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms182717(v=sql.105).aspx" target="_blank">IF</a> statement, taking the parameter into account.  The parameter is a boolean value so when it’s True, it equals to 1.</p>
<p>And here’s the full statement for the dataset:</p>
<pre class="code"><span style="color: blue;">if </span>@WithStockData <span style="color: gray;">= </span>1
    <span style="color: green;">-- sales and stock data
    </span><span style="color: blue;">select </span>P<span style="color: gray;">.</span>ProductNumber<span style="color: gray;">, </span>P<span style="color: gray;">.</span>Name
        <span style="color: gray;">, </span>P<span style="color: gray;">.</span>SafetyStockLevel<span style="color: gray;">, </span>P<span style="color: gray;">.</span>ReorderPoint
        <span style="color: gray;">, </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span>SOD<span style="color: gray;">.</span>OrderQty<span style="color: gray;">) </span>SoldQuantity<span style="color: gray;">, </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span>I<span style="color: gray;">.</span>Quantity<span style="color: gray;">) </span>InventoryQuantity
        <span style="color: gray;">, </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span>I<span style="color: gray;">.</span>Quantity<span style="color: gray;">) - </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span>SOD<span style="color: gray;">.</span>OrderQty<span style="color: gray;">) </span>CurrentStock
    <span style="color: blue;">from </span>Production<span style="color: gray;">.</span>Product P
    <span style="color: gray;">inner join </span>Sales<span style="color: gray;">.</span>SalesOrderDetail SOD <span style="color: blue;">on </span>SOD<span style="color: gray;">.</span>ProductID <span style="color: gray;">= </span>P<span style="color: gray;">.</span>ProductID
    <span style="color: gray;">inner join </span>Production<span style="color: gray;">.</span>ProductInventory I <span style="color: blue;">on </span>I<span style="color: gray;">.</span>ProductID <span style="color: gray;">= </span>P<span style="color: gray;">.</span>ProductID
    <span style="color: blue;">group by </span>P<span style="color: gray;">.</span>ProductNumber<span style="color: gray;">, </span>P<span style="color: gray;">.</span>Name<span style="color: gray;">, </span>P<span style="color: gray;">.</span>SafetyStockLevel<span style="color: gray;">, </span>P<span style="color: gray;">.</span>ReorderPoint
    <span style="color: blue;">order by </span>CurrentStock<span style="color: gray;"> </span><span style="color: blue;">asc
else
    </span><span style="color: green;">-- regular sales data
    </span><span style="color: blue;">select </span>P<span style="color: gray;">.</span>ProductNumber<span style="color: gray;">, </span>P<span style="color: gray;">.</span>Name
        <span style="color: gray;">, </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span>SOD<span style="color: gray;">.</span>OrderQty<span style="color: gray;">) </span>SoldQuantity
    <span style="color: blue;">from </span>Production<span style="color: gray;">.</span>Product P
    <span style="color: gray;">inner join </span>Sales<span style="color: gray;">.</span>SalesOrderDetail SOD <span style="color: blue;">on </span>SOD<span style="color: gray;">.</span>ProductID <span style="color: gray;">= </span>P<span style="color: gray;">.</span>ProductID
    <span style="color: blue;">group by </span>P<span style="color: gray;">.</span>ProductNumber<span style="color: gray;">, </span>P<span style="color: gray;">.</span>Name
    <span style="color: blue;">order by </span>P<span style="color: gray;">.</span>ProductNumber <span style="color: blue;">asc</span><span style="color: gray;">;</span></pre>
<p>Some data as returned by the SELECT in the <em>then</em> part:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The sales and stock data: 7 fields in total" src="http://blog.hoegaerden.be/wp-content/uploads/image452.png" border="0" alt="The sales and stock data: 7 fields in total" width="700" height="128" /></p>
<p>And some data as returned by the query in the <em>else</em> part:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The regular sales data only consists of three columns" src="http://blog.hoegaerden.be/wp-content/uploads/image453.png" border="0" alt="The regular sales data only consists of three columns" width="327" height="97" /></p>
<p>As you can clearly see, the first query returns seven fields while the second one contains only three.  You can also see that both results are ordered differently.</p>
<p>Now, let’s get the fun started!  Create a new report, set up a data source that points to the AdventureWorks2008R2 database and create a dataset with the query above:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Setting up the dataset" src="http://blog.hoegaerden.be/wp-content/uploads/image454.png" border="0" alt="Setting up the dataset" width="629" height="642" /></p>
<p><span style="text-decoration: underline;">Power tip:</span> to create the dataset, do not right-click on the Datasets node in the Report Data pane, but right-click on the <strong>Data Source</strong> and then select <strong>Add Dataset</strong>.  That saves you some work because the Data Source will be pre-populated.  All you need to do is paste the query in the <strong>Query</strong> field and give it a decent <strong>Name</strong>.</p>
<p>Click the OK button to close the Dataset Properties.</p>
<p>Now open the new dataset in the Report Data pane and count its fields:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Our dataset contains seven fields!" src="http://blog.hoegaerden.be/wp-content/uploads/image455.png" border="0" alt="Our dataset contains seven fields!" width="285" height="166" /></p>
<p>You should come to seven!  How nice, all of our fields are there.  This is not always the case, but I’ll handle that later.</p>
<p>The Parameters node in the Report Data pane should now contain a new parameter called @WithStockData:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The @WithStockData parameter got created automatically" src="http://blog.hoegaerden.be/wp-content/uploads/image456.png" border="0" alt="The @WithStockData parameter got created automatically" width="149" height="98" /></p>
<p>Double-click it to get to its properties and change the <strong>Data type</strong> to <em>Boolean</em> (by default it’s <em>Text</em>).</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The WithStockData parameter properties" src="http://blog.hoegaerden.be/wp-content/uploads/image457.png" border="0" alt="The WithStockData parameter properties" width="585" height="482" /></p>
<p>If you want, you can also specify a default value.  The value should be either “true” or “false”:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Our Boolean parameter is set to false as default" src="http://blog.hoegaerden.be/wp-content/uploads/image458.png" border="0" alt="Our Boolean parameter is set to false as default" width="585" height="482" /></p>
<p>With the dataset fully set up, let’s now move on to visualizing it.</p>
<h3>Displaying Dynamic Columns</h3>
<p>Put a <strong>Table</strong> on the report Design and set it up as follows:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image459.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The Table contains seven columns" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb105.png" border="0" alt="The Table contains seven columns" width="700" height="60" /></a></p>
<p>All seven columns have been added.</p>
<p>One step remains: even though the values won’t always be present, the columns will not disappear automatically.  To take care of that, we’ll enter an expression on the <strong>Hidden</strong> property of each column.  Each column in a dataset has got the <strong>IsMissing</strong> property.  When its value is True, it means that the column is not present and should thus be hidden.</p>
<p>The expression looks like this:</p>
<pre class="code">=Fields!InventoryQuantity.IsMissing</pre>
<p>Or visually:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Using the IsMissing property to hide a column dynamically" src="http://blog.hoegaerden.be/wp-content/uploads/image460.png" border="0" alt="Using the IsMissing property to hide a column dynamically" width="577" height="641" /></p>
<p>To set up the expression, click the grey area above the column title to select it and then locate the <strong>Hidden</strong> property in the <strong>Properties</strong> pane.  Do this for each dynamic column (don&#8217;t forget to change the column name in the expression). If you need to get white space removed, switch the Row/Column Groups to Advanced Mode and locate the  Hidden property of the appropriate <em>(Static)</em> item in the Column Groups.</p>
<p>And here’s what the rendered report looks like:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image461.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Report with all columns displayed" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb106.png" border="0" alt="Report with all columns displayed" width="700" height="228" /></a></p>
<p>Once more, with the parameter set to False:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The report showing sales data only" src="http://blog.hoegaerden.be/wp-content/uploads/image462.png" border="0" alt="The report showing sales data only" width="482" height="264" /></p>
<p>The four stock-related columns are nicely hidden!  And the ordering is working as well because we’ve taken care of that in the dataset’s queries.</p>
<p>Easy, huh?  Well, yeah, but I’ve made sure that the process went as smoothly as possible.  It takes some knowledge on how SSRS actually works.  Let’s make this clear by adapting the example just a little.</p>
<h3>Understanding The Dataset</h3>
<p>Delete the current dataset and create a new one, using the following statement (ensure that you give it the same name as the original one):</p>
<pre class="code"><span style="color: blue;">if </span>@WithStockData <span style="color: gray;">= </span>0
    <span style="color: green;">-- regular sales data
    </span><span style="color: blue;">select </span>P<span style="color: gray;">.</span>ProductNumber<span style="color: gray;">, </span>P<span style="color: gray;">.</span>Name
        <span style="color: gray;">, </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span>SOD<span style="color: gray;">.</span>OrderQty<span style="color: gray;">) </span>SoldQuantity
    <span style="color: blue;">from </span>Production<span style="color: gray;">.</span>Product P
    <span style="color: gray;">inner join </span>Sales<span style="color: gray;">.</span>SalesOrderDetail SOD <span style="color: blue;">on </span>SOD<span style="color: gray;">.</span>ProductID <span style="color: gray;">= </span>P<span style="color: gray;">.</span>ProductID
    <span style="color: blue;">group by </span>P<span style="color: gray;">.</span>ProductNumber<span style="color: gray;">, </span>P<span style="color: gray;">.</span>Name
    <span style="color: blue;">order by </span>P<span style="color: gray;">.</span>ProductNumber <span style="color: blue;">asc
else
    </span><span style="color: green;">-- sales and stock data
    </span><span style="color: blue;">select </span>P<span style="color: gray;">.</span>ProductNumber<span style="color: gray;">, </span>P<span style="color: gray;">.</span>Name
        <span style="color: gray;">, </span>P<span style="color: gray;">.</span>SafetyStockLevel<span style="color: gray;">, </span>P<span style="color: gray;">.</span>ReorderPoint
        <span style="color: gray;">, </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span>SOD<span style="color: gray;">.</span>OrderQty<span style="color: gray;">) </span>SoldQuantity<span style="color: gray;">, </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span>I<span style="color: gray;">.</span>Quantity<span style="color: gray;">) </span>InventoryQuantity
        <span style="color: gray;">, </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span>I<span style="color: gray;">.</span>Quantity<span style="color: gray;">) - </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span>SOD<span style="color: gray;">.</span>OrderQty<span style="color: gray;">) </span>CurrentStock
    <span style="color: blue;">from </span>Production<span style="color: gray;">.</span>Product P
    <span style="color: gray;">inner join </span>Sales<span style="color: gray;">.</span>SalesOrderDetail SOD <span style="color: blue;">on </span>SOD<span style="color: gray;">.</span>ProductID <span style="color: gray;">= </span>P<span style="color: gray;">.</span>ProductID
    <span style="color: gray;">inner join </span>Production<span style="color: gray;">.</span>ProductInventory I <span style="color: blue;">on </span>I<span style="color: gray;">.</span>ProductID <span style="color: gray;">= </span>P<span style="color: gray;">.</span>ProductID
    <span style="color: blue;">group by </span>P<span style="color: gray;">.</span>ProductNumber<span style="color: gray;">, </span>P<span style="color: gray;">.</span>Name<span style="color: gray;">, </span>P<span style="color: gray;">.</span>SafetyStockLevel<span style="color: gray;">, </span>P<span style="color: gray;">.</span>ReorderPoint
    <span style="color: blue;">order by </span>CurrentStock<span style="color: gray;"> </span><span style="color: blue;">asc</span><span style="color: gray;">;</span></pre>
<p>The only difference with the previous version is that the IF condition is reversed and thus the two queries are swapped.</p>
<p>Now render the report.  What do you see?</p>
<blockquote><p>An error occurred during local report processing.</p>
<p>The definition of the report ‘/DynamicDataset’ is invalid.</p>
<p>The Hidden expression for the text box ‘Textbox7’ refers to the field ‘InventoryQuantity’. Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope.</p>
<p>Letters in the names of fields must use the correct case.</p></blockquote>
<p>Oh my, it’s broken!</p>
<p>Now take a good look at the available dataset fields:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The dataset only has three columns, oh my!" src="http://blog.hoegaerden.be/wp-content/uploads/image463.png" border="0" alt="The dataset only has three columns, oh my!" width="241" height="100" /></p>
<p>That’s right, only three!  Four of them have gone missing!  The reason for that is because SSRS uses the first SELECT query it encounters in the whole statement to determine the available fields.  It’s not able to automatically detect the different situations and create all the fields that can possibly be returned.</p>
<p>One way to ensure all fields are created is to put the query that returns all possible fields as first query, which is what I initially did.  But of course that’s not always an option.</p>
<h3>Manually Adding Fields To A Dataset</h3>
<p>Luckily it’s possible to manually add fields to the dataset.  You can do this by clicking the <strong>Add</strong> button in the <strong>Fields</strong> page of the <strong>Dataset Properties</strong> and then selecting <strong>Query Field</strong>.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Manually adding additional fields to the dataset" src="http://blog.hoegaerden.be/wp-content/uploads/image464.png" border="0" alt="Manually adding additional fields to the dataset" width="643" height="265" /></p>
<p>So, add the four missing fields:</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="The four additional fields added manually" src="http://blog.hoegaerden.be/wp-content/uploads/image465.png" border="0" alt="The four additional fields added manually" width="454" height="245" /></p>
<p>If you now render the report, it should behave exactly the same as in the initial version!</p>
<h3>What About Those Warnings?</h3>
<p>If you’re someone who pays attention to the Error List pane, you may have noticed some warnings.  Two for each dynamic field to be exact.</p>
<p>Here’s an example of the <strong>rsMissingFieldInDataSet</strong> warning:</p>
<blockquote><p>Warning    1    [rsMissingFieldInDataSet] The dataset ‘dsProductSales’ contains a definition for the Field ‘SafetyStockLevel’. This field is missing from the returned result set from the data source.    C:\test\SSRS\SSRS2008\DynamicDataset.rdl    0    0</p></blockquote>
<p>And here’s the <strong>rsErrorReadingDataSetField</strong> warning:</p>
<blockquote><p>Warning    2    [rsErrorReadingDataSetField] The dataset ‘dsProductSales’ contains a definition for the Field ‘SafetyStockLevel’. The data extension returned an error during reading the field. There is no data for the field at position 4.    C:\test\SSRS\SSRS2008\DynamicDataset.rdl    0    0</p></blockquote>
<p>I’ve got a developer background, so I always try to remove all warnings.  So if you really want to get rid of those warnings too, even that’s possible.  But it will require some Custom Code writing.  I already covered that topic some years ago, when I wrote an article about <a title="SSRS and MDX: Detecting Missing Fields" href="http://blog.hoegaerden.be/2009/07/06/ssrs-and-mdx-detecting-missing-fields/" target="_blank">Detecting Missing Fields</a>.</p>
<h2>Conclusion</h2>
<p>With this article I believe to have demonstrated that datasets can be quite flexible, even though it doesn’t always seem so.</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%2F2012%2F03%2F20%2Fbuilding-reports-with-dynamic-datasets%2F&amp;title=Building%20Reports%20With%20Dynamic%20Datasets" 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/2012/03/20/building-reports-with-dynamic-datasets/feed/</wfw:commentRss>
		<slash:comments>0</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_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/06/11/passing-a-datetime-parameter-into-the-execute-sql-task/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
