处理SSRS中的多值参数

时间:2017-07-11 07:05:38

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

我的SSRS上有6 filters,其中1 is of Department。我必须选择multiple departments并根据这些选择生成报告。但我不知道如何完成这件事。

我创建了一个stored procedure,它在Reports中被调用。

ALTER PROC [dbo].[usp_getLessonLearntDetails]
@AssetID nvarchar(50),
@DepartmentID nvarchar(50),
@Category varchar(50),
@AuditType varchar(50),
@AuditStartYear nvarchar(50),
@AuditEndYear nvarchar(50)

AS

BEGIN

SELECT 
ROW_NUMBER() OVER(ORDER BY AssetName ASC) AS Sno,
LLD.LessonComputedID, tbl_Asset.AssetName, AT.AuditType, SY.Year+' - '+EY.Year as 'Audit Period',
DE.DepartmentName, CT.CategoryName, LLD.Learnings, 
CAST(CASE WHEN (LLD.RepeatedObservation = 1) THEN 'True' ELSE 'False' END AS varchar(10)) as RepeatedObservation, 
LLD.RepeatedObservationReference, Att.Attachment
FROM         tbl_LessonLearntDetails LLD INNER JOIN
             tbl_Category CT ON CT.CategoryID = LLD.Title  INNER JOIN
             tbl_Asset ON LLD.AssetID = tbl_Asset.AssetID INNER JOIN
             tbl_Department DE ON LLD.DepartmentID = DE.DepartmentID INNER JOIN
             tbl_AuditType AT ON LLD.AuditTypeID = AT.AuditTypeID INNER JOIN
             tbl_Attachment Att ON LLD.LessonLearntID= Att.LeassonLearntID INNER JOIN
             tbl_AuditYear SY on SY.Year = LLD.AuditStartYear INNER JOIN                   
             tbl_AuditYear EY on EY.Year = LLD.AuditEndYear

        where ( (('0'=@AssetID and (1=1)) or LLD.AssetID=@AssetID) and 
                (('0'=@DepartmentID and (1=1)) or LLD.DepartmentID IN (@DepartmentID)) and
                (('0'=@Category and (1=1)) or LLD.Title=@Category) and
                (('0'=@AuditType and (1=1)) or LLD.AuditTypeID=@AuditType) and
                (('0'=@AuditStartYear and (1=1)) or (LLD.AuditStartYear >= @AuditStartYear)) and
                (('0'=@AuditEndYear and (1=1)) or (LLD.AuditEndYear <= @AuditEndYear))
              );

END;

1 个答案:

答案 0 :(得分:0)

使用分割功能可以在这里工作。我做到了。

在where where条件下,使用split功能。

(('0'=@DepartmentID AND (1=1)) OR LLD.DepartmentID IN (SELECT * FROM fnSplit(@DepartmentID,',')))

感谢大家的回复。因为你们只有我才能被分裂的想法所打击。