views:

374

answers:

3

Similar to this question: link

However I have already mastered that. My problem is a new report we just added at work has values for parameters (i.e.:10-New, 20-Cancel, 30-Complete). For the life of me, I cannot figure out how to pass multiple values for the same parameter. (so from the previous example, choosing 10-New and 30-Complete as values for the parameter).

Can this be done? And if so, how?

+1  A: 

I believe you do it the same way as any other report, you just comma separate your list (i.e. 10,20), which is why you need a function to split your comma separated string into a table for your where clause (sounds like you've already got this covered)

MasterMax1313
wait, what? The SQL Report Service server has a report viewer URL (see that other post if you are not sure what I am talking about), it automatically parses parameters with a built in routine to display the report. I have no control over that. I have tried a comma, and it does not accept that.
IPX Ares
If you've got your SQL stored in the report, you don't have to worry about that. If you've got it in a Stored Procedure, then SSRS passes in the multi-value parameter in as a comma delimited string, which you then have to parse out or convert into a table. http://msdn.microsoft.com/en-us/library/aa337396%28SQL.90%29.aspx
MasterMax1313
that is odd, still does not work, but that was the article I was not able to track down. I will forward this back to our report team. Thanks.
IPX Ares
A: 

If you are passing mutiple values to a paremeter, first make sure the parameter is marked to allow multiple values.

Then in your query make sure you use some sort of split function to separate out the string.

HLGEM
A: 

You don't have to split it. You can do the following...

Ensure that the first, and last values in the comma-delim string are enclosed by quotes (I use a udf to do this)...

IF CHARINDEX(',', @Param) <> 1 SET @Value = ',' + @Value

IF CHARINDEX(',', REVERSE(@Value)) <> 1 SET @Value = @Value + ','

Then, enclose yur field that will be filtered in commas and wild-card expresion and use a LIKE comparison to filter your clause...

SELECT t.Field1 , t.Field2 FROM dbo.Table1 t WHERE '%,' + t.Field + ',%' LIKE @Parm

Works like a dream on any string fields, but can get tricky with dates and integers, etc. You will then have to also CAST the field you are filtering to a VARCHAR.

Scott