Multi value parameter SSRS 2008

I am having troubles while trying to get a multi-value parameter query to work from SSRS 2008. After much perusing of the web and EE, nothing quite seems to work.

I have built a test SSRS report which should return 3 records. If I type the "in" statement directly in SQL SP it works fine. When I use the SSRS multi-value parameter I get only the first of three records returned.

First, in the SSRS report's Dataset Parameters section I declare the following:
@pProject =join(Parameters!pProject.Value, ",")

When running the report, I get the first of three values back. I am using a function from Angellll to handle the parameter. I am calling the parameter in the SP by using this:

SELECT        project, project_desc
FROM            projectsinfo
WHERE        project in ( select rtrim(value) from dbo.parmsToList(@pProject,','))

If I change this code to use this where statement:
where project in ('01360006', '01490102', '01880052')

I get three records back as expected.

Any help is appreciated.
alter FUNCTION [dbo].[ParmsToList] (@Parameters varchar(max), @delimiter varchar(10) ) 
returns @result TABLE (Value varchar(max)) 
AS   
begin 
    declare @dx varchar(9) 
    -- declare @loops int 
     --set @loops = 0 
  
     DECLARE @TempList table 
          ( 
          Value varchar(8000) 
          ) 
  
     if @delimiter is null  set @delimiter = ' ' 
     if datalength(@delimiter) < 1 set @delimiter = ' ' 
     set @dx = left(@delimiter, datalength(@delimiter)-1) 
  
     DECLARE @Value varchar(8000), @Pos int 
  
     SET @Parameters = LTRIM(@Parameters)+ @delimiter 
     SET @Pos = CHARINDEX(@delimiter, @Parameters, 1) 
  
     IF REPLACE(@Parameters, @delimiter, @dx) <> '' 
     BEGIN 
          WHILE @Pos > 0 -- AND @Loops < 100 
          BEGIN 
               --set @loops = @loops + 1 
               SET @Value = LEFT(@Parameters, @Pos - 1) 
               IF @Value <> '' 
               BEGIN 
                    INSERT INTO @TempList (Value) VALUES (@Value) --Use Appropriate conversion 
               END 
               SET @Parameters = SUBSTRING(@Parameters, @Pos+ datalength(@delimiter), 8000) 
               SET @Pos = CHARINDEX(@delimiter, @Parameters, 1) 
  
          END 
     END     
     INSERT @result 
     SELECT value 
        FROM @TempList 
     RETURN 
END

Open in new window

mirthlessAsked:
Who is Participating?
 
conrabaConnect With a Mentor Commented:
I see nothing wrong on the function or even when running the nvarchar values againts the function. Have you tried just running the SQL statement returned from the profiler if you get the 3 records back.  Can you post the proc or the SQL that you are using in the report, I want to see how the @pProject was declared.
0
 
conrabaCommented:
I trust that you've checked  thye function will return 3 records when
SET @pProject = '01360006, 01490102, 01880052' is used in:
select rtrim(value) from dbo.parmsToList(@pProject,',')

How about the the value of the parameter that is generated from the report
@pProject =join(Parameters!pProject.Value, ",")
are they equal to '01360006, 01490102, 01880052'  or similar format ?
0
 
mirthlessAuthor Commented:
when I run:
select rtrim(value) from dbo.parmsToList('01360006, 01490102, 01880052',',')
I get three values returned in a table-like format.


When I run profiler at the report using the parameter value of:
=join(Parameters!pProject.Value, ",")
I get @pProject=N'01360006 ,01490102 ,01880052 '
return.jpg
0
 
mirthlessAuthor Commented:
You got it man, I had the parameter too short, it was varchar(16)!  After I set it longer all works as expected.
0
 
conrabaCommented:
Glad to help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.