SSRS中的Twp多选参数在选择多个值

时间:2016-04-29 16:40:21

标签: sql sql-server stored-procedures reporting-services

我遇到SSRS报告没有填充第二个多值下拉列表的问题,该列表依赖于第一个多值下拉列表,因此没有填充报告。

所以,我在这里要做的是从第一个下拉列表中为选定城市的建筑承包商填写SSRS报告,从第二个下拉列表中选择技能集,一旦我们选择城市下拉列表,就会填充。

但我的问题是,当我选择一个城市时,技能的下拉列表会毫无问题地填充,当我选择多个城市时,我的技能下拉显示没有价值。

我的代码如下。我有3个数据集。

数据集1(主要)

ALTER PROCEDURE [dbo].[RPT_ADM_Total_Contractors]

    @Office nvarchar(255),
    @Start datetime,
    @End datetime,
    @Servicetype nvarchar(255)

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    SELECT    fs.skillname,fa.NEW_ContractorIDNAME AS ContractorName, fa.new_Contractorstatusname AS Contractorstatus,
          fa.createdon AS CreatedDate, fa.new_addresscity AS City
    FROM 
        Filterednew_contrator fa
    join
        FilteredService fs
    on fa.new_service = fs.serviceid

    WHERE 
    fa.new_sitename IN (@Office )
    AND fs.skillname IN (@Servicetype)


END

数据集2

ALTER PROCEDURE [dbo].[RPT_ADM_Total_Contractors_Officelist]
    @Start date,
    @End date
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

        SELECT DISTINCT fa.new_sitename
    FROM 
        Filterednew_contrator fa
    join
        FilteredService fs
    on fa.new_service = fs.serviceid    
    WHERE       
        new_admitdate between @Start and @End
        AND new_sitename like 'Office%'
        fa.new_service is not null

END

数据集3

ALTER PROCEDURE [dbo].[RPT_ADM_Total_Contractors_Servicetypelist]

        @Office nvarchar(255)
        --@Start datetime,
        --@End datetime

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    SELECT DISTINCT fs.skillname
    FROM 
        Filterednew_contrator fa
    join
        FilteredService fs
    on fa.new_service = fs.serviceid
    WHERE
    fa.new_sitename in (@Office)        
    order by fs.skillname


END

我有4个参数

@Start date/time
@End date/time
@Office "Allow Multivalue" AND gets populated from dataset 2
@Servicetype "Allow Mutivalue" AND gets populated from dataset 3

我尝试使用= Join(参数!Office.Value,“,”)但是没有用。 我希望有人可以帮我解决这个问题。

感谢。

1 个答案:

答案 0 :(得分:1)

您有2个选项。

选项1.使SSRS下拉列表成为单个值下拉列表。

如果这不是一个可行的选择,那么这里是选项2:

您将不得不在存储过程中为@Office和@Servicetype参数创建类似于(n)varchar(1000)的数据类型;足够长的东西来处理具有所有可能值的字符串。然后,您必须将字符串拆分为单个值,以便可以在IN子句中使用它们。这是我过去使用的分割UDF(并在此网站上多次发布)。

class='loaded-large'

在适当的位置(在数据库中),您可以在WHERE子句中将SP代码更改为这样。

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 

享受!