SSRS Records Not Showing Up When (Select All) Is Used But Is When Selecting A Particular Value

强颜欢笑 提交于 2019-12-02 12:16:05

问题


I have a report that is has a multiple value parameter. It has available values (1, 2, 3, 4, 5, and blank). The blank value isn't NULL it is just an empty cell.

For testing purposes, there should only be one record showing up. The record has a blank value in the cell that I am using to filter on in my stored procedure.

In the parameter drop down, I see all of the options. If I choose the (Select All) option, I don't get the record I am wanting. However, if I choose just the blank value, I get the record I am wanting. I updated the record manually to "2". I choose (Select All) and I get the record. I choose only the "2" value and I get the record. If I remove the value again to make the value blank, I only get the record if I only choose the "Blank" option in the drop down.

I make a text box to output the value of the parameter and it is showing blank when it is selected either by itself or with other values.

What am I missing in either my stored procedure or in my report? Thanks in advance.


回答1:


When you have a multiple select parameter, SSRS should send a comma separated list of values to your stored procedure. You are responsible for splitting these back out into something that you can join on.

In the report itself, you don't get the list of values in a nicely wrapped up string for displaying. I've had to use code to iterate over the values in the parameter.

I tested what SSRS is doing when you have a blank available value. I created a test report that had the six available options and then a stored procedure to force the selected values to be output:

CREATE PROCEDURE dbo.Test_RPT
(
 @TestMultiSelect varchar(1000)
)
AS
SELECT @TestMultiSelect RVAL

In the report, I just had a single textbox that displayed this RVAL field.

If I put the blank option at the start, the output was 1,2,3,4,5. If the blank option was at any other location, it was included: 1,2,3,,4,5, 1,2,3,4,5,.




回答2:


If you want to pass multiple values to Sql IN clause within a Stored Procedure from SSRS report dataset, slight changes needed in the Stored Procedure:

See the Sample WHERE clause in a SP

...  
AND Courses.Type_Code IN (@Type_Code)

Add a SplitString() function to split the passed parameters based on a delimiter.

The body of the SplitString() will look like:

CREATE FUNCTION [dbo].[SplitString]
(
    @pString VARCHAR(8000), 
    @pDelimiter CHAR(1)
)
RETURNS @Values TABLE (Value VARCHAR(50))
AS
BEGIN

        DECLARE @xml as XML;

        SET @xml = cast(('<X>'+replace(@pString, @pDelimiter, '</X><X>')+'</X>') as xml);

        INSERT @Values
        SELECT N.value('.', 'varchar(50)') as value 
        FROM @xml.nodes('X') as T(N);

        RETURN
END;

Finally the IN clause will looks like:

...
AND Courses.Type_Code IN (SELECT * FROM dbo.SplitString(@type_code,','))


来源:https://stackoverflow.com/questions/33242006/ssrs-records-not-showing-up-when-select-all-is-used-but-is-when-selecting-a-pa

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