Welcome to EMC Consulting Blogs Sign in | Join | Help

Steve Wright's Blog

I am also posting my updates to the following location: http://zogamorph.blogspot.com

Working With Reporting Services Multiple Value Parameters

A couple of colleagues of mine were working on a complicated reporting services project; they had one report which had a parameter which allowed a user to select multiple values of numbers, the problem they were facing was how pass the selected values into the query.

They were looking for a way within SQL Server to split a string by a delimiter. As they were using a stored procedure to access the data and multiple value parameters, regardless of parameter type, are passed in as a string of comma separated values.

One thing which they weren’t aware of was that with a multiple value parameter, the behaviour can differ between how the data is being retrieved i.e.: stored procedure or embed sql statement.

If the data set is using direct query to gather the data then the multi value parameter can be used in the query with a IN clause like so:

Where column1 in (@pMultiValueParam)

What happens is that before the query is sent to the SQL Server the query the report server substitutes the @pMulitValueParam with a comma separated list which makes it valid in clause like so:

Where column1 in (10, 3, 4, 56)

Also it has been blogged (http://www.socha.com/blogs/john/2009/03/tfs-report-issues-with-sql-server-2008.html) that in reporting services 2008 there is a new change in the behaviour. You could see the following message when you have no values to select:

Incorrect syntax near ')'.

When there are no values to pass, Reporting Services 2008 simply removes @pMultiValueParam, so you get something like "Where column1 in ()" preventing this query from running.

The solution is to add an expression to the pMultiValueParam report parameter. The expression is evaluated in order to determine what is passed to the query.

Like so:

=IIF(Parameters! pMultiValueParam.Count > 0, Parameters!pMultiValueParam.Value, "")

Published 30 March 2009 10:09 by steve.wright

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

jamie.thomson said:

Nice tip. I've been having problems with this myself just recently!

March 30, 2009 13:05
 

jamie.thomson said:

Nice! Just had to use this - works beautifully. Didn't realise you could put expressions on dataset query parameters.

Cheers Wrighty!!

April 23, 2009 15:09
 

Kila said:

Nice job!

But What if the multiple value parameter is a list of String?

July 27, 2009 15:25
 

steve.wright said:

This would work perfectly for string type multiple value parameter as then you would be passing in an empty string.  Where you might need to have different substitute value for an empty multiple value parameter is then the list should have been numbers.

August 14, 2009 17:51
 

Steven Bell said:

The reason this does not work for a list of strings is that the IN clause is not right...

SQL created by SSRS query:

WHERE (column1 IN ('Value1,Value2'))

Proper SQL:

WHERE (column1 IN ('Value1','Value2'))

September 13, 2010 19:23
 

Vijay said:

I have problem with numeric values. When I enter comma separated value, say 1,2,3 in parameter, it gives me can't conver from nvarchar to bigint.

I have following query WHERE (column1 IN (@entervalue))

Any help?

March 31, 2011 00:24
 

HKM said:

Nice, I solved my problem using this. Huge timesaver!

June 1, 2011 17:34

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication

News

Locations of visitors to this page
Powered by Community Server (Personal Edition), by Telligent Systems