选择所有在SSRS上无法正常工作

时间:2017-06-12 07:04:35

标签: sql-server reporting-services ssrs-2012

我创建了关于SSRS的报告。报告参数允许多个值。 当我选择"允许多个值"属性,参数下拉列表显示我"选择全部"但是当我选择"选择所有"报告结果不正确。

我为我的报告创建了所有选择。当我选择" all"我的报告结果显示正确。

你知道我可以删除"选择所有"当我使用"允许多个值"? 或者我该如何解决这个问题?

这些是我的参数: 我已经选择了所有"和#34;所有"在我的下拉列表中: enter image description here

当我选择"所有"对于我的所有参数,我的报告结果将为真: enter image description here

当我选择"选择所有"对于我的所有参数,我的报告结果将是错误的: enter image description here

脚本

这是我的主要脚本: 注意:SplitString是我的功能,它分割参数值

    ALTER PROCEDURE [dbo].[Material_Lot_Properties_Report]

    @MATERIAL_TYPE VARCHAR(50)
    ,@MATERIAL_CLASS VARCHAR(50)
    , @MATERIAL VARCHAR(50)
    ,@PROPERTYID VARCHAR(50)
    ,@PVALUE VARCHAR(50)

    AS

    --*/

    BEGIN
     SET NOCOUNT ON

    DECLARE @TYPIES AS TABLE
        (
            TYPE VARCHAR(10)
        )

    INSERT INTO @TYPIES 
    SELECT * 
    FROM [dbo].[SplitString] (@MATERIAL_TYPE,',')
    --SELECT * FROM @TYPIES


    DECLARE @CLASSES AS TABLE
        (
            CLASS VARCHAR(10)
        )

    INSERT INTO @CLASSES 
    SELECT * 
    FROM [dbo].[SplitString] (@MATERIAL_CLASS,',')
    --SELECT * FROM @CLASSES



    DECLARE @MATERIALS AS TABLE
        (
            MATERIAL VARCHAR(10)
        )

    INSERT INTO @MATERIALS 
    SELECT * 
    FROM [dbo].[SplitString] (@MATERIAL,',')
    --SELECT * FROM @MATERIALS


    DECLARE @PROPERTIES AS TABLE
        (
            PROPERTY VARCHAR(50)
        )

    INSERT INTO @PROPERTIES 
    SELECT * 
    FROM [dbo].[SplitString] (@PROPERTYID,',')
    --SELECT * FROM @PROPERTIES




    DECLARE @VALUES AS TABLE
        (
            VALUE VARCHAR(50)
        )

    INSERT INTO @VALUES 
    SELECT * 
    FROM [dbo].[SplitString] (@PVALUE,',')
    --SELECT * FROM @VALUES




    SELECT 
            M.STR_TYPE      [TYPE],
            M.STR_CLASS     [CLASS],
            DEFID,
            DEFNAME,
            L.LOTID,
            PROPERTYID,
            P.PVALUE
    FROM [DBO].[MMWLOTS] L
        JOIN  [DBO].[MMWLOTPRPVALS]  P
    ON P.LOTPK=L.LOTPK
        JOIN [DBO].[LFP_MATERIALS] M
    ON M.STR_MATERIAL_ID=L.DEFID
        WHERE P.PValue IS NOT NULL
            AND (@MATERIAL_TYPE= '<All>' OR  M.STR_TYPE IN (SELECT * FROM @TYPIES))
            AND (@MATERIAL_CLASS= '<All>' OR  M.STR_CLASS IN (SELECT * FROM @CLASSES))
            AND (@MATERIAL= '<All>' OR M.STR_MATERIAL_ID IN (SELECT * FROM @MATERIALS))
            AND (@PROPERTYID= '<All>' OR PropertyID IN (SELECT * FROM @PROPERTIES))
            AND (@PVALUE = '<All>' OR PVALUE IN (SELECT * FROM @VALUES))


    END

这是我的分割功能:

ALTER FUNCTION [dbo].[SplitString] 
( 
    @string NVARCHAR(MAX), 
    @delimiter CHAR(1) 
) 
RETURNS @output TABLE(splitdata NVARCHAR(MAX) 
) 
BEGIN 
    DECLARE @start INT, @end INT 
    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string) 
    WHILE @start < LEN(@string) + 1 BEGIN 
        IF @end = 0  
            SET @end = LEN(@string) + 1

        INSERT INTO @output (splitdata)  
        VALUES(SUBSTRING(@string, @start, @end - @start)) 
        SET @start = @end + 1 
        SET @end = CHARINDEX(@delimiter, @string, @start)

    END 
    RETURN 
END

这是我的类参数脚本:

  ALTER PROCEDURE [dbo].[Material_Lot_Properties_Report_for_Class_Parameter]

    @MATERIAL_TYPE VARCHAR(50)


    AS

    --*/

    BEGIN
     SET NOCOUNT ON




    DECLARE @TYPIES AS TABLE
        (
            TYPE VARCHAR(10)
        )

    INSERT INTO @TYPIES 
    SELECT * 
    FROM [dbo].[SplitString] (@MATERIAL_TYPE,',')
    --SELECT * FROM @TYPIES

        SELECT '<All>' 'CLASS'
    UNION
    SELECT DISTINCT M.STR_CLASS     CLASS
    FROM [DBO].[MMWLOTS] L
        JOIN  [DBO].[MMWLOTPRPVALS]  P
    ON P.LOTPK=L.LOTPK
        JOIN [DBO].[MATERIALS] M
    ON M.STR_MATERIAL_ID=L.DEFID
        WHERE P.PValue IS NOT NULL
        AND (@MATERIAL_TYPE= '<All>' OR  M.STR_TYPE IN (SELECT * FROM @TYPIES))


    END

2 个答案:

答案 0 :(得分:1)

由于你还没有包含你的数据集脚本,这就是我可以走的尽可能没有进入可能毫无意义的猜测的世界,更新你的答案以包含这个,你将获得更有针对性的回应

看起来您的报表参数曾经是一个单值参数,其中手动添加了<All>选项,或者构建此报表的任何人都不知道多值参数在SSRS中的工作方式。

如果您将参数设置为多值,则SSRS会自动添加(Select All)选项,并按字面顺序勾选每个框。勾选的每个选项都会作为可在in()语句中使用的值传递给您的查询,如下所示:

select Col1
      ,Col2
from Table
where Col2 in(@SSRSParameter)

看起来您的查询实际设置为以与此类似的方式处理单个值或文字“

select Col1
      ,Col2
from Table
where Col2 = @SSRSParameter
   or @SSRSParameter = '<All>'

如果您现在从多值参数传递值,则会出现意外行为。

答案 1 :(得分:-1)

这是我的主要脚本: 注意:SplitString是我的功能,它分割参数值

    ALTER PROCEDURE [dbo].[Material_Lot_Properties_Report]

    @MATERIAL_TYPE VARCHAR(50)
    ,@MATERIAL_CLASS VARCHAR(50)
    , @MATERIAL VARCHAR(50)
    ,@PROPERTYID VARCHAR(50)
    ,@PVALUE VARCHAR(50)

    AS

    --*/

    BEGIN
     SET NOCOUNT ON

    DECLARE @TYPIES AS TABLE
        (
            TYPE VARCHAR(10)
        )

    INSERT INTO @TYPIES 
    SELECT * 
    FROM [dbo].[SplitString] (@MATERIAL_TYPE,',')
    --SELECT * FROM @TYPIES


    DECLARE @CLASSES AS TABLE
        (
            CLASS VARCHAR(10)
        )

    INSERT INTO @CLASSES 
    SELECT * 
    FROM [dbo].[SplitString] (@MATERIAL_CLASS,',')
    --SELECT * FROM @CLASSES



    DECLARE @MATERIALS AS TABLE
        (
            MATERIAL VARCHAR(10)
        )

    INSERT INTO @MATERIALS 
    SELECT * 
    FROM [dbo].[SplitString] (@MATERIAL,',')
    --SELECT * FROM @MATERIALS


    DECLARE @PROPERTIES AS TABLE
        (
            PROPERTY VARCHAR(50)
        )

    INSERT INTO @PROPERTIES 
    SELECT * 
    FROM [dbo].[SplitString] (@PROPERTYID,',')
    --SELECT * FROM @PROPERTIES




    DECLARE @VALUES AS TABLE
        (
            VALUE VARCHAR(50)
        )

    INSERT INTO @VALUES 
    SELECT * 
    FROM [dbo].[SplitString] (@PVALUE,',')
    --SELECT * FROM @VALUES




    SELECT 
            M.STR_TYPE      [TYPE],
            M.STR_CLASS     [CLASS],
            DEFID,
            DEFNAME,
            L.LOTID,
            PROPERTYID,
            P.PVALUE
    FROM [DBO].[MMWLOTS] L
        JOIN  [DBO].[MMWLOTPRPVALS]  P
    ON P.LOTPK=L.LOTPK
        JOIN [DBO].[LFP_MATERIALS] M
    ON M.STR_MATERIAL_ID=L.DEFID
        WHERE P.PValue IS NOT NULL
            AND (@MATERIAL_TYPE= '<All>' OR  M.STR_TYPE IN (SELECT * FROM @TYPIES))
            AND (@MATERIAL_CLASS= '<All>' OR  M.STR_CLASS IN (SELECT * FROM @CLASSES))
            AND (@MATERIAL= '<All>' OR M.STR_MATERIAL_ID IN (SELECT * FROM @MATERIALS))
            AND (@PROPERTYID= '<All>' OR PropertyID IN (SELECT * FROM @PROPERTIES))
            AND (@PVALUE = '<All>' OR PVALUE IN (SELECT * FROM @VALUES))


    END

这是我的分割功能:

ALTER FUNCTION [dbo].[SplitString] 
( 
    @string NVARCHAR(MAX), 
    @delimiter CHAR(1) 
) 
RETURNS @output TABLE(splitdata NVARCHAR(MAX) 
) 
BEGIN 
    DECLARE @start INT, @end INT 
    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string) 
    WHILE @start < LEN(@string) + 1 BEGIN 
        IF @end = 0  
            SET @end = LEN(@string) + 1

        INSERT INTO @output (splitdata)  
        VALUES(SUBSTRING(@string, @start, @end - @start)) 
        SET @start = @end + 1 
        SET @end = CHARINDEX(@delimiter, @string, @start)

    END 
    RETURN 
END

这是我的类参数脚本:

  ALTER PROCEDURE [dbo].[Material_Lot_Properties_Report_for_Class_Parameter]

    @MATERIAL_TYPE VARCHAR(50)


    AS

    --*/

    BEGIN
     SET NOCOUNT ON




    DECLARE @TYPIES AS TABLE
        (
            TYPE VARCHAR(10)
        )

    INSERT INTO @TYPIES 
    SELECT * 
    FROM [dbo].[SplitString] (@MATERIAL_TYPE,',')
    --SELECT * FROM @TYPIES

        SELECT '<All>' 'CLASS'
    UNION
    SELECT DISTINCT M.STR_CLASS     CLASS
    FROM [DBO].[MMWLOTS] L
        JOIN  [DBO].[MMWLOTPRPVALS]  P
    ON P.LOTPK=L.LOTPK
        JOIN [DBO].[MATERIALS] M
    ON M.STR_MATERIAL_ID=L.DEFID
        WHERE P.PValue IS NOT NULL
        AND (@MATERIAL_TYPE= '<All>' OR  M.STR_TYPE IN (SELECT * FROM @TYPIES))


    END