﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Adriaan Davel / Article Discussions / Article Discussions by Author  / Multi-Select Parameters for Reporting Services / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 12:03:32 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>I'm running against Oracle.  My query works fine with these small chages to Oracle syntax:WHERE (:CommaDelimtedList  || ',' LIKE '%' ||  TableColumnToCompareTo  || ',%' OR @CommaDelimtedList = '')However when I run the query in Reporting Services 2005 Sp2, if I choos more than one item in the multiselect, I get the error"ORA-00920 Invalid relational operator"  Any idea what is happening?</description><pubDate>Fri, 17 Sep 2010 11:54:17 GMT</pubDate><dc:creator>vze47pt5</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>Beautiful...it worked great!</description><pubDate>Fri, 19 Mar 2010 16:34:11 GMT</pubDate><dc:creator>cerayg</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>how can we write a query and pass multi value parameters to stored procedure in the report? To exec a procedure we simply writeExec MyStoredProcedure to exec a stored procedure we need to pass parameters. I can do Exec MyStoredProcedure IN (@ParamList)I have gone through this thread conversations however, I am not able to make out when to use Split function and how to use.In dataset, which query I need to write to exec a stored procedure with multi value parameters.</description><pubDate>Mon, 22 Oct 2007 11:44:45 GMT</pubDate><dc:creator>Jaishree</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>This is only for reports that run occasionally.  most users select 1 to 3 clients, so it is not high on our list at this time to optimize this</description><pubDate>Mon, 20 Aug 2007 05:51:00 GMT</pubDate><dc:creator>Jim Parzych</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;Hi Philippe,&lt;/P&gt;&lt;P&gt;Thanks for the post. This was the one option we considered but did not test as we were running on a SQL2000 database and I had never worked with CLR on SQL2000. I would imagine that this would be a good solution as C\C++\C# is normally better as string manipulation than SQL.&lt;/P&gt;</description><pubDate>Sun, 19 Aug 2007 23:44:00 GMT</pubDate><dc:creator>Adriaan Davel</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;Hi sebastian,&lt;/P&gt;&lt;P&gt;I don't normally use indexes on temp tables as building the index is often more costly than not using it. In this case we did test it with, and without indexes and the overall performance was better without the index.&lt;/P&gt;&lt;P&gt;My rule of thumb for indexes is to only create then if they will be used more than once, then the cost of building the index will be less than scanning the table. With temp tables this is mostly true.&lt;/P&gt;</description><pubDate>Sun, 19 Aug 2007 23:40:00 GMT</pubDate><dc:creator>Adriaan Davel</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;Hi dph,&lt;/P&gt;&lt;P&gt;Have you done performance testing on this with large tables? I try to avoid "LIKE" statements as much as possible as they have a tendancy to cause table scans. I would be interested to see your performance testing results.&lt;/P&gt;</description><pubDate>Sun, 19 Aug 2007 23:37:00 GMT</pubDate><dc:creator>Adriaan Davel</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;Your approach is the same as what we did, and found it to be highly inefficient, have you done some perfonace testing on big tables and wide range of parameter selections?&lt;/P&gt;</description><pubDate>Sun, 19 Aug 2007 23:33:00 GMT</pubDate><dc:creator>Adriaan Davel</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;Hi Jon,&lt;/P&gt;&lt;P&gt;Interesting idea. Have you tested this against large tables? This would result in a table scan which might have a big impact on performance...&lt;/P&gt;</description><pubDate>Sun, 19 Aug 2007 23:31:00 GMT</pubDate><dc:creator>Adriaan Davel</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;Hi SDM,&lt;/P&gt;&lt;P&gt;It could well be that my results were affected by our table size and parameter length as it was a fairly large table and many parameter options (strings) selected. I'm sure a smaller table and less parameters would have different results. We decided to stick with the dynamics SQL as to advantages out weigh the disadvantages.&lt;/P&gt;&lt;P&gt;In the query plan computations stood out most (as expected) and the join was very in-efficient, which is what I expected as well.&lt;/P&gt;</description><pubDate>Sun, 19 Aug 2007 23:27:00 GMT</pubDate><dc:creator>Adriaan Davel</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;Hi Jose,&lt;/P&gt;&lt;P&gt;We tried to split the string into records, and insert it into a temp table yes, and it had some perfomance boost but the cost of splitting the string and inserting into a temp table cause performance to be less than using dynamic sql...&lt;/P&gt;</description><pubDate>Sun, 19 Aug 2007 23:14:00 GMT</pubDate><dc:creator>Adriaan Davel</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;If you want to avoid dynamic SQL, you could use an UDF that will convert comma-delimited string to a table-type variable, and then use IN as usual.&lt;/P&gt;&lt;P&gt;SELECT * FROM customers &lt;/P&gt;&lt;P&gt;WHERE ISNULL(@cust_id_multiple, '') = '' OR customers.cust_id IN (SELECT value FROM dbo.LIST_TO_TABLE(@cust_id_multiple))&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Below is a sample UDF that does the trick.&lt;/P&gt;&lt;P&gt;--converts list of values to a temporary table. Used to avoid dynamic SQL statements when IN clause is used as filter expression--sList: list of numeric values in comma-separated form, to be converted to table --return value: table-type variable containing one column. The table is filled with numeric values from @sListCREATE FUNCTION LIST_TO_TABLE (@sList AS VARCHAR(255))RETURNS  @retTable TABLE(value VARCHAR(50))  AS  &lt;/P&gt;&lt;P&gt;BEGIN &lt;/P&gt;&lt;P&gt; IF @sList IS NULL RETURN&lt;/P&gt;&lt;P&gt; --preparing the input list, removing IN keyword and parenthesis SET @sList = REPLACE(@sList, 'IN(','') SET @sList = REPLACE(@sList, 'IN (','') SET @sList = REPLACE(@sList, '(','') SET @sList = REPLACE(@sList, ')','') SET @sList = LTRIM(RTRIM(@sList))&lt;/P&gt;&lt;P&gt; --scrolling thru values in @sList and populating temporary table DECLARE @Index INT, @Delimiter CHAR(1) DECLARE @Result VARCHAR(255)&lt;/P&gt;&lt;P&gt; SET @Delimiter = ','&lt;/P&gt;&lt;P&gt; WHILE @sList &amp;lt;&amp;gt; '' BEGIN  SET @Index = CHARINDEX(@Delimiter, @sList)  IF @Index &amp;lt;&amp;gt; 0  BEGIN   SET @Result = LEFT(@sList, @Index - 1)   SET @sList = SUBSTRING(@sList, @Index + 1, LEN(@sList))  END  ELSE  BEGIN   SET @Result = @sList   SET @sList = ''  END&lt;/P&gt;&lt;P&gt;  INSERT @retTable SELECT @Result END&lt;/P&gt;&lt;P&gt; RETURN &lt;/P&gt;&lt;P&gt;END&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Wed, 15 Aug 2007 06:33:00 GMT</pubDate><dc:creator>Wapper</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;If you want to use an IN try this?&lt;/P&gt;&lt;P&gt;WHERE RealTableColumn IN (SELECT TempTableColumn FROM TempTable)&lt;/P&gt;&lt;P&gt;EXISTS can be fast too but not sure in this scenario.&lt;/P&gt;&lt;P&gt;WHERE EXISTS (SELECT TempTableColumn FROM TempTable WHERE TempTableColumn = RealTableColumn)&lt;/P&gt;&lt;P&gt;However a JOIN on an indexed TempTableField should be as fast as anything in my experience.&lt;/P&gt;&lt;P&gt;I would normally use the IN option as it is clearer.&lt;/P&gt;</description><pubDate>Tue, 14 Aug 2007 07:18:00 GMT</pubDate><dc:creator>Luke-458024</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>Hello,I have been using all these solutions and finally settled for a CLR function that I found on the Internet.It works great for me.Regards,Philippeusing System;using System.Data;using System.Data.SqlClient;using System.Data.SqlTypes;using Microsoft.SqlServer.Server;public partial class UserDefinedFunctions{    [Microsoft.SqlServer.Server.SqlFunction(IsDeterministic = true, IsPrecise = true, TableDefinition = "SQLStr nvarchar(4000)", FillRowMethodName = "FillSplitCommaDelimitedStringToStr")]    public static System.Collections.IEnumerable clrfn_SplitCommaDelimitedString(SqlString str)    {        string x = str.Value;        if (!string.IsNullOrEmpty(x))        {            return x.Split(',');        }        else        {            return null;        }    }    private static void FillSplitCommaDelimitedStringToStr(object obj, out SqlString str)    {        if (obj != null)            str = (String)(obj);        else            str = String.Empty;    }};''I call it like thatWhere (@PTI2 = '##' or  b.PTI2_Cd in (select  ltrim(SQLstr) from ONGlobals.dbo.clrfn_SplitCommaDelimitedString(@Pti2) ) )''The ## is used for cases where we want all values.</description><pubDate>Mon, 13 Aug 2007 11:12:00 GMT</pubDate><dc:creator>Philippe Cand</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;Adriaan,&lt;/P&gt;&lt;P&gt;When you create the temp table, was included a index for the join column ?, the performance between a table without index vs an indexes table in this case can be very big. &lt;/P&gt;&lt;P&gt;Example: The customer table have the next structure:&lt;/P&gt;&lt;P&gt;create table customer (  id         int primary key, state    int, LName   varchar(100), rname    varchar(100))&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;and supose that table have an index on the state column create index IDX_Customer_State on Customer (state)&lt;/P&gt;&lt;P&gt;so, we temp table have the next code&lt;/P&gt;&lt;P&gt;declare @TempJoinTable (IdState    int   primary key) //note the primary key, we can index a @temptable like anyone&lt;/P&gt;&lt;P&gt;the next step is to populate the temp table with this code&lt;/P&gt;&lt;P&gt;-- the @FilterValue contain the filter values with comma &lt;/P&gt;&lt;P&gt;DECLARE @posicion     INTDECLATE @Value        VARCHAR(100)&lt;/P&gt;&lt;P&gt;WHILE (Len(@FilterValue))BEGIN&lt;/P&gt;&lt;P&gt;     SET @Posicion = PATINDEX('%,%',@FilterValue)     IF (@Posicion = 0)     BEGIN          SET @Value = @FilterValue          SET @FilterValue = ''     END     ELSE     BEGIN          SET @Value = SUBSTRING(@FilterValue,1,@Posicion-1)          SET @FilterValue = SUBSTRING(@FilerValue,@Posicion+1,LEN(@FilterValue)     END&lt;/P&gt;&lt;P&gt;     INSERT INTO @TempJoinTable VALUES (@Value)&lt;/P&gt;&lt;P&gt;END&lt;/P&gt;&lt;P&gt;finally, just join the tables and compare the execution time&lt;/P&gt;&lt;P&gt;SELECT *FROM customer CUS     INNER JOIN @TempJoinTable TT         ON CUS.State = TT.IdState    &lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Mon, 13 Aug 2007 08:18:00 GMT</pubDate><dc:creator>sebastian rodriguez</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;We faced this problem a while back at our company as well.  And one of our DBAs came up with the following solution:WHERE (@CommaDelimtedList + ',' LIKE '%'+ TableColumnToCompareTo + ',%' OR @CommaDelimtedList = '')Just thought I'd share with everyone how we handle this situation.&lt;/P&gt;</description><pubDate>Mon, 13 Aug 2007 07:55:00 GMT</pubDate><dc:creator>dph-446223</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>i approach it a little differently.  I use a function to split a parameter value into its different piecesI also provide an All option with -1 being the value passed to the stored procedure.my stored procedure has this line:AND       (s.ORDERCODE IN (SELECT Item FROM dbo.Split(@OrderCode,',')) OR '-1' IN(@OrderCode))and function Split looks like this:SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE FUNCTION [dbo].[Split](	@ItemList NVARCHAR(4000), 	@delimiter CHAR(1))RETURNS @IDTable TABLE (Item VARCHAR(50))  AS      BEGIN    	DECLARE @tempItemList NVARCHAR(4000)	SET @tempItemList = @ItemList	DECLARE @i INT    	DECLARE @Item NVARCHAR(4000)	SET @tempItemList = REPLACE (@tempItemList, ''' ''', '')	SET @i = CHARINDEX(@delimiter, @tempItemList)	WHILE (LEN(@tempItemList) &gt; 0)	BEGIN		IF @i = 0			SET @Item = @tempItemList		ELSE			SET @Item = LEFT(@tempItemList, @i - 1)		INSERT INTO @IDTable(Item) VALUES(@Item)		IF @i = 0			SET @tempItemList = ''		ELSE			SET @tempItemList = RIGHT(@tempItemList, LEN(@tempItemList) - @i)		SET @i = CHARINDEX(@delimiter, @tempItemList)	END 	RETURNEND  </description><pubDate>Mon, 13 Aug 2007 06:46:00 GMT</pubDate><dc:creator>Jim Parzych</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>I would love to see a code example from Adriaan's article as well.</description><pubDate>Mon, 13 Aug 2007 06:27:00 GMT</pubDate><dc:creator>Justin D Loranger</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>If you use parameterized dynamic sql in the stored procedure, it shouldn't differ from the query within the report. What I'd try is dump the SSRS parameters, do it with my own code, and pass an xml full of parameters (sql 2005).</description><pubDate>Mon, 13 Aug 2007 03:53:00 GMT</pubDate><dc:creator>Ronald Green</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;no need for dynamic SQL, just use something like this:&lt;/P&gt;&lt;P&gt;WHERE &lt;FONT color=#ff00ff size=2&gt;charindex&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;','&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; field1 &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;','&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;','&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; @param1 &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;','&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT size=2&gt; 0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;&lt;/FONT&gt; &lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;... where @param1 is a string of comma-delimited values.&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Mon, 13 Aug 2007 03:52:00 GMT</pubDate><dc:creator>Jon Spink</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;Thanks for the post Adriaan. It would be great if you could paste some sample code here!&lt;/P&gt;&lt;P&gt;Nick&lt;/P&gt;</description><pubDate>Mon, 13 Aug 2007 03:12:00 GMT</pubDate><dc:creator>Nick Thompson-356919</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>&lt;P&gt;Adriaan,&lt;/P&gt;&lt;P&gt;I'm rather surprised at the blow-out to ten minutes for that basic shred-the-tokenised-string-to-a-table approach.  I've done this several times as a way of dealing with SSRS multi-select, and found it fine for performance (although really it's a bit crude and hack-y).&lt;/P&gt;&lt;P&gt;Was there anything obvious in the  query plan (of the porly performing query) to indicate why this was such a bad thing to do?  &lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Mon, 13 Aug 2007 02:00:00 GMT</pubDate><dc:creator>SDM</dc:creator></item><item><title>RE: Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>Have you tried to have it stored in a table with that function of yours and do a select statement but instead of join using  @parameter in (select parameter from @table) to see if that boost the performance?And could you publish de code of said function?Thanks in advance</description><pubDate>Mon, 13 Aug 2007 01:36:00 GMT</pubDate><dc:creator>jose antonio segurado</dc:creator></item><item><title>Multi-Select Parameters for Reporting Services</title><link>http://www.sqlservercentral.com/Forums/Topic386759-399-1.aspx</link><description>Comments posted here are about the content posted at &lt;A HREF="http://www.sqlservercentral.com/columnists/ADavel/3138.asp"&gt;http://www.sqlservercentral.com/columnists/ADavel/3138.asp&lt;/A&gt;</description><pubDate>Tue, 31 Jul 2007 12:01:00 GMT</pubDate><dc:creator>Adriaan Davel</dc:creator></item></channel></rss>