如何在SSRS中编写表达式来过滤数据

时间:2017-02-09 20:15:05

标签: sql-server reporting-services expression

我需要根据参数值过滤我的结果。如果它显示"Open",那么DueDate列应为= NULL,,如果说'Closed' DueDate = NOT NULL,如果它显示"Both"那么它应该抓住所有DueDateŠ

我创建了查询参数"状态"这给了我3个可能的值:

enter image description here

接下来,我创建了报告参数"Status"Allow Multiple Values

enter image description here

现在我转到我的主查询并转到过滤器:

enter image description here

在这里,我无法理解如何写一个表达说:

如果报告"状态"值="打开"然后告诉我DueDate为NULL的结果, 如果报告"状态"值="已关闭"那么DueDate不是NULL, 如果报告"状态"值="两者"然后告诉我所有DueDates(null和not null)

另一件事是我的查询中已经有了case语句:

ALTER Procedure
AS
@ShowOpen bit = 0,
@ShowClosed bit = 0
 SELECT
 FROM 
 WHERE 
              AND
                        (
                        (CASE WHEN (@ShowOpen = 1) THEN
                              CASE WHEN (tblNoteRecipients.CompletedDate IS NULL and tblNoteRecipients.IsDiary = 1) or tblNoteRecipients.UserGUID is null THEN 1 ELSE 0 END
                             -- CASE WHEN (tblNoteRecipients.CompletedDate IS NULL) THEN 1 ELSE 0 END
                        ELSE
                              1
                        END = 1)
                  AND
                        (CASE WHEN (@ShowClosed = 1) THEN
                              CASE WHEN (tblNoteRecipients.CompletedDate IS NULL) THEN 0 ELSE 1 END
                        ELSE
                              1
                        END = 1)
                  OR    ((@ShowOpen = 1) AND (@ShowClosed = 1))
                        )

在SSRS中有什么办法可以创建接受值Open,Closed和Both的参数吗?

添加了test1

enter image description here

1 个答案:

答案 0 :(得分:1)

在Tablix中添加一个过滤器,如下所示:

enter image description here

Expression中使用:

=IIF(
(Array.IndexOf(Parameters!Status.Value,"Open")>-1 and 
Isnothing(Fields!DueDate.Value)) or
(Array.IndexOf(Parameters!Status.Value,"Closed")>-1 and not 
Isnothing(Fields!DueDate.Value)) or
(Array.IndexOf(Parameters!Status.Value,"Both")>-1),
 "Include","Exclude")

Value使用:

="Include"

如果有帮助,请告诉我。