<?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>Dutton Software &#187; Multi-value parameters</title>
	<atom:link href="http://www.duttonsoftware.com/tag/multi-value-parameters/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.duttonsoftware.com</link>
	<description>Code, plug-ins &#38; more</description>
	<lastBuildDate>Mon, 16 Jan 2012 06:30:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Non-queried multi-value parameters in SQL Server Reporting Services</title>
		<link>http://www.duttonsoftware.com/2008/12/05/non-queried-multi-value-parameters-in-sql-server-reporting-services/</link>
		<comments>http://www.duttonsoftware.com/2008/12/05/non-queried-multi-value-parameters-in-sql-server-reporting-services/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 07:39:49 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[SQL Server Reporting Services]]></category>
		<category><![CDATA[Multi-value parameters]]></category>
		<category><![CDATA[non-queried parameters]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://www.duttonsoftware.com/?p=117</guid>
		<description><![CDATA[As a follow-up to my previous post on Easy multi-value parameters in SQL Server Reporting Services, I wanted to point out some information on non-queried, or static multi-value parameters. For my example, I&#8217;m using a parameter named &#8220;Time&#8221; with choices &#8220;Morning&#8221;, &#8220;Noon&#8221;, and &#8220;Night&#8221;.  The values are M, N, and I respectively.  You can see [...]]]></description>
			<content:encoded><![CDATA[<p>As a follow-up to my previous post on <a title="Easy multi-value parameters in SQL Server Reporting Services" href="http://www.duttonsoftware.com/2008/09/25/easy-multi-value-parameters-in-sql-server-reporting-services/" target="_self">Easy multi-value parameters in SQL Server Reporting Services</a>, I wanted to point out some information on non-queried, or static multi-value parameters.</p>
<p>For my example, I&#8217;m using a parameter named &#8220;Time&#8221; with choices &#8220;Morning&#8221;, &#8220;Noon&#8221;, and &#8220;Night&#8221;.  The values are M, N, and I respectively.  You can see how I set up the parameter in the following screenshot.</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/12/multi-value-parameters-non-queried-default-dialog.png"><img class="alignnone size-full wp-image-118" title="multi-value-parameters-non-queried-default-dialog" src="http://www.duttonsoftware.com/wp-content/uploads/2008/12/multi-value-parameters-non-queried-default-dialog.png" alt="" width="500" height="393" /></a></p>
<p>You can accomplish having all the checkboxes selected by default in two ways.  The first way is to pass an object array of values, and the easiest way to do that is to use the Split command to split a string into a string array.  I used <strong>=Split(&#8220;M,N,I&#8221;,&#8221;,&#8221;)</strong> as my default.  I had to provide the second parameter for Split, the delimiter, because the default is space.</p>
<p>The second, and easier method, is to just add a line item for each item you want checked, as demonstrated in this screenshot:</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/12/multi-value-parameters-non-queried-default-simple-method.png"><img class="alignnone size-full wp-image-123" title="multi-value-parameters-non-queried-default-simple-method" src="http://www.duttonsoftware.com/wp-content/uploads/2008/12/multi-value-parameters-non-queried-default-simple-method.png" alt="" width="459" height="153" /></a></p>
<p>Here is the resulting parameter list, showing all the items selected (same for either method):</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/12/multi-value-parameters-non-queried-default-results.png"><img class="alignnone size-full wp-image-119" title="multi-value-parameters-non-queried-default-results" src="http://www.duttonsoftware.com/wp-content/uploads/2008/12/multi-value-parameters-non-queried-default-results.png" alt="" width="244" height="56" /></a></p>
<p>Sometimes, you need to display the parameters of your report, perhaps so it could be regenerated later.  You&#8217;ll need to print out that object array, so use the opposite of Split, <strong>Join</strong>.  Below is a textbox with an expression of <strong>=Join(Parameters!Time.Label, &#8220;, &#8220;)</strong>, which joins the parameter values together with a comma and space separator.</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/12/multi-value-parameters-non-queried-display-label-code.png"><img class="alignnone size-full wp-image-120" title="multi-value-parameters-non-queried-display-label-code" src="http://www.duttonsoftware.com/wp-content/uploads/2008/12/multi-value-parameters-non-queried-display-label-code.png" alt="" width="299" height="72" /></a></p>
<p>Here is the result of the code, with two parameters selected shown:</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/12/multi-value-parameters-non-queried-display-label-results.png"><img class="alignnone size-full wp-image-121" title="multi-value-parameters-non-queried-display-label-results" src="http://www.duttonsoftware.com/wp-content/uploads/2008/12/multi-value-parameters-non-queried-display-label-results.png" alt="" width="254" height="154" /></a></p>
<p>If you only put the parameter label in the textbox (i.e. using code <strong>=Parameters!Time.Label</strong>) then when you display the report, you&#8217;ll get the famous Reporting Services #Error message.  You have to use <strong>Join</strong> in this case.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.duttonsoftware.com/2008/12/05/non-queried-multi-value-parameters-in-sql-server-reporting-services/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Easy multi-value parameters in SQL Server Reporting Services</title>
		<link>http://www.duttonsoftware.com/2008/09/25/easy-multi-value-parameters-in-sql-server-reporting-services/</link>
		<comments>http://www.duttonsoftware.com/2008/09/25/easy-multi-value-parameters-in-sql-server-reporting-services/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 05:26:50 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[SQL Server Reporting Services]]></category>
		<category><![CDATA[Multi-value parameters]]></category>
		<category><![CDATA[Report parameters]]></category>
		<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://www.duttonsoftware.com/?p=19</guid>
		<description><![CDATA[I recently came across an application where I needed to use a multi-value parameter in SQL Server Reporting Services (SSRS).  I always seemed to have trouble with these in the past.  This time I found them very easy to use because I found (re-discovered?) a simple way. The basic idea is to set up a [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across an application where I needed to use a multi-value parameter in SQL Server Reporting Services (SSRS).  I always seemed to have trouble with these in the past.  This time I found them very easy to use because I found (re-discovered?) a simple way.</p>
<p>The basic idea is to set up a parameter as if it were going to be a single value parameter with the topmost row selected by default.  I will walk through the steps of this scenario.</p>
<p>I chose the AdventureWorks database to do this sample and focused on June 2004 Sales to get an easy dataset to work with.</p>
<p>1. Create the basic dataset:</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/salesbyterritory-dataset.jpg"><img class="size-full wp-image-30 alignnone" title="salesbyterritory-dataset" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/salesbyterritory-dataset.jpg" alt="Sales By Territory Dataset" width="315" height="454" /></a></p>
<p>2. Set up the layout for the report:</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/june-2004-sales-by-territory-layout.jpg"><img class="alignnone size-full wp-image-22" title="june-2004-sales-by-territory-layout" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/june-2004-sales-by-territory-layout.jpg" alt="" width="500" height="247" /></a></p>
<p>3. Preview the report with no parameters:</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/june-2004-sales-by-territory-preview.jpg"><img class="alignnone size-full wp-image-23" title="june-2004-sales-by-territory-preview" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/june-2004-sales-by-territory-preview.jpg" alt="" width="372" height="468" /></a></p>
<p>4. Create a new dataset for the territories list:</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/terroritylist-dataset.jpg"><img class="alignnone size-full wp-image-33" title="terroritylist-dataset" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/terroritylist-dataset.jpg" alt="" width="299" height="434" /></a></p>
<p>5. Set up the parameter, <strong>TerritoryID</strong>, like a normal single-value parameter.  Be sure to set the default value to make it default to the topmost row in the list.  In this case, the topmost is &#8220;Australia&#8221;, TerritoryID of 9.</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/report-parameters-dialog-single-parameter.jpg"><img class="alignnone size-full wp-image-29" title="report-parameters-dialog-single-parameter" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/report-parameters-dialog-single-parameter.jpg" alt="" width="500" height="387" /></a></p>
<p>6a. Apply the filter to the table.  Notice that I am not editing the dataset, but simply adding a filter to the table properties.  If you are usually the type to edit the dataset (like myself), just hang with me for a second.  Right-click the edge of the table and then choose <strong>Properties</strong>:</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/design-table-properties.jpg"><img class="alignnone size-full wp-image-21" title="design-table-properties" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/design-table-properties.jpg" alt="" width="394" height="414" /></a></p>
<p>6b.  Modify the table properties to add the filter.  Since you can&#8217;t read it all, it says</p>
<pre>=Fields!TerritoryID.Value = Parameters!TerritoryID.Value</pre>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/table-properties-applying-filter.jpg"><img class="alignnone size-full wp-image-31" title="table-properties-applying-filter" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/table-properties-applying-filter.jpg" alt="" width="448" height="432" /></a></p>
<p>7. Check the finished result.  We now have a report with a single parameter.  The topmost selection, Australia, is automatically selected and our filter is applied by default.</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/preview-single-parameter-and-filter-applied.jpg"><img class="alignnone size-full wp-image-34" title="preview-single-parameter-and-filter-applied" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/preview-single-parameter-and-filter-applied.jpg" alt="" width="377" height="300" /></a></p>
<p>8. So far, so good&#8211;there is nothing extraordinary about what we&#8217;ve done so far.  Now, we simple make the parameter multi-value by changing the report parameters and checking the <strong>Multi-value</strong> box:</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/report-parameters-dialog-multi-value-checked.jpg"><img class="alignnone size-full wp-image-28" title="report-parameters-dialog-multi-value-checked" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/report-parameters-dialog-multi-value-checked.jpg" alt="" width="500" height="387" /></a></p>
<p>9. Don&#8217;t rush off just yet, or you&#8217;ll see this error message when you choose <strong>Preview</strong>:</p>
<address>An error occurred during local report processing.</address>
<address>An error has occurred during report processing.</address>
<address>The processing of FilterExpression for the table &#8216;Sales&#8217; cannot be performed. Cannot compare data of types System.Byte and System.Object[].  Please check the data type returned by the Filter Expression.<br />
</address>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/preview-rushing-into-errors.jpg"><img class="alignnone size-full wp-image-27" title="preview-rushing-into-errors" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/preview-rushing-into-errors.jpg" alt="" width="480" height="220" /></a></p>
<p>10.  You need to make one small change to the filter.  Open the table properties again, but this time change the operator from equals (=) to IN.  Since the Parameters!TerritoryID.Value now contains a comma separated list, we need to search IN instead of comparing.</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/table-properties-applying-multi-value-filter.jpg"><img class="alignnone size-full wp-image-32" title="table-properties-applying-multi-value-filter" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/table-properties-applying-multi-value-filter.jpg" alt="" width="448" height="432" /></a></p>
<p>11. Now, preview your report.  The left image shows the initial preview, the right image shows the drop-down list blown out, you can see that Select All is selected by default.</p>
<p><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/preview-multi-value-select-all-filter-applied.jpg"><img class="alignnone size-medium wp-image-25" title="preview-multi-value-select-all-filter-applied" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/preview-multi-value-select-all-filter-applied-275x300.jpg" alt="" width="275" height="300" /></a><a href="http://www.duttonsoftware.com/wp-content/uploads/2008/09/preview-multi-value-select-all-filter-selected-by-default.jpg"><img class="alignnone size-medium wp-image-26" title="preview-multi-value-select-all-filter-selected-by-default" src="http://www.duttonsoftware.com/wp-content/uploads/2008/09/preview-multi-value-select-all-filter-selected-by-default-279x300.jpg" alt="" width="279" height="300" /></a></p>
<p>One caveat is that performance is not going to be top notch because Reporting Services is filtering on the entire dataset every time.  It would (most likely, depending on your implementation) be faster to filter in the dataset.  However, this approach often requires a lot of development work on the T-SQL side to get it working.  This approach is easy and quick enough for many applications.  Enjoy.</p>
<p>Update: I found a good example of <a href="http://www.eggheadcafe.com/software/aspnet/31022159/ssrs-multivalue-paramete.aspx" target="_blank">the hard way to do multi-value parameters (by using SQL)</a>.  If you scroll down to the second post, there is source code there for converting a delimited string into a table variable.  I have re-formatted the <a href="http://www.duttonsoftware.com/wp-content/uploads/2008/10/charlist_to_table.sql">charlist_to_table source code</a> to make it more legible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.duttonsoftware.com/2008/09/25/easy-multi-value-parameters-in-sql-server-reporting-services/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

