SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Multi-Select Parameters for Reporting Services


Multi-Select Parameters for Reporting Services

Author
Message
Adriaan Davel
Adriaan Davel
SSC Veteran
SSC Veteran (239 reputation)SSC Veteran (239 reputation)SSC Veteran (239 reputation)SSC Veteran (239 reputation)SSC Veteran (239 reputation)SSC Veteran (239 reputation)SSC Veteran (239 reputation)SSC Veteran (239 reputation)

Group: General Forum Members
Points: 239 Visits: 13
Comments posted here are about the content posted at http://www.sqlservercentral.com/columnists/ADavel/3138.asp
jose antonio segurado
jose antonio segurado
SSC Rookie
SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)

Group: General Forum Members
Points: 33 Visits: 4
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
SDM
SDM
Right there with Babe
Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)

Group: General Forum Members
Points: 734 Visits: 401

Adriaan,

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).

Was there anything obvious in the query plan (of the porly performing query) to indicate why this was such a bad thing to do?





Nick Thompson-356919
Nick Thompson-356919
Valued Member
Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)

Group: General Forum Members
Points: 53 Visits: 12

Thanks for the post Adriaan. It would be great if you could paste some sample code here!

Nick


Jon Spink
Jon Spink
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1678 Visits: 945

no need for dynamic SQL, just use something like this:

WHERE charindex(',' + field1 + ',',',' + @param1 + ',') > 0

... where @param1 is a string of comma-delimited values.


Ronald Green
Ronald Green
Old Hand
Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)

Group: General Forum Members
Points: 338 Visits: 144
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).
Justin D Loranger
Justin D Loranger
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 135
I would love to see a code example from Adriaan's article as well.
Jim Parzych
Jim Parzych
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 91
i approach it a little differently. I use a function to split a parameter value into its different pieces

I 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 ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE 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) > 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
RETURN
END



dph-446223
dph-446223
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 2

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.


sebastian rodriguez
sebastian rodriguez
Valued Member
Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)

Group: General Forum Members
Points: 58 Visits: 102

Adriaan,

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.

Example: The customer table have the next structure:

create table customer (
id int primary key
, state int
, LName varchar(100)
, rname varchar(100))

and supose that table have an index on the state column
create index IDX_Customer_State on Customer (state)

so, we temp table have the next code

declare @TempJoinTable (IdState int primary key) //note the primary key, we can index a @temptable like anyone

the next step is to populate the temp table with this code

-- the @FilterValue contain the filter values with comma

DECLARE @posicion INT
DECLATE @Value VARCHAR(100)

WHILE (Len(@FilterValue))
BEGIN

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

INSERT INTO @TempJoinTable VALUES (@Value)

END

finally, just join the tables and compare the execution time

SELECT *
FROM customer CUS
INNER JOIN @TempJoinTable TT
ON CUS.State = TT.IdState



Sebastián Rodríguez R.
Licenciado en Informática de Gestión
sebas_rod@hotmail.com
(569) - 98626471
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search