SSRS 2008 report not working with using a stored procedure

时间秒杀一切 提交于 2019-12-04 21:29:18

Sounds like you are passing in values from a dropdown that allows the end user to select more than one value. If this is the situation, then SSRS sends those values to the stored procedure in one long string. The more values that are checked in the dropdown, the longer the string. If the end user only checks one value, then everything will work in this situation (your IN clause can deal with just one value).

You have 2 options. Option 1. Make the SSRS dropdown a single value dropdown.

If that is not a viable option, then here is option 2:

You are going to have to make the data type for the @report parameter in the stored procedure something like an (n)varchar(1000); something long enough to handle a string with all possible values. Then you have to split the string into individual values so you can use them in the IN clause. Here is a split UDF I have used in the past.

CREATE FUNCTION [dbo].[udf_Split] 
   (  @List      varchar(8000), 
      @Delimiter varchar(5)
   ) 
   RETURNS @TableOfValues table 
      (  RowID   smallint IDENTITY(1,1), 
         [Value] varchar(100) 
      ) 
AS 
   BEGIN

      DECLARE @LenString int 

      WHILE len( @List ) > 0 
         BEGIN 

            SELECT @LenString = 
               (CASE charindex( @Delimiter, @List ) 
                   WHEN 0 THEN len( @List ) 
                   ELSE ( charindex( @Delimiter, @List ) -1 )
                END
               ) 

            INSERT INTO @TableOfValues 
               SELECT substring( @List, 1, @LenString )

            SELECT @List = 
               (CASE ( len( @List ) - @LenString ) 
                   WHEN 0 THEN '' 
                   ELSE right( @List, len( @List ) - @LenString - 1 ) 
                END
               ) 
         END

      RETURN 

   END 

Once you have that in place, you can change you code to look like this.

IF 1 IN (SELECT value FROM dbo.udf_Split(@report, ','))

You may have to tweak this UDF to work with integers in your case, but the implicit conversion of data types may not be a problem. Or, change the data type in your SSRS dropdown to string.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!