简体   繁体   English

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

[英]how to write an expression in SSRS to filter data

I need to filter my result based on Parameter value.我需要根据参数值过滤我的结果。 If it says "Open" then DueDate column should be = NULL, if says 'Closed' that DueDate = NOT NULL , and if it says "Both" then it should grab all DueDate s如果显示"Open" ,则DueDate列应为= NULL,如果显示'Closed' ,则DueDate = NOT NULL ,如果显示"Both" ,则应获取所有DueDate s

I have created query parameter "Status" that gives me 3 possible values:我创建了查询参数“Status”,它给了我 3 个可能的值:

在此处输入图像描述

Next I created report parameter "Status" and Allow Multiple Values接下来我创建了报告参数"Status"Allow Multiple Values

在此处输入图像描述

Now I go to my main query and go to Filters:现在我转到我的主要查询并转到过滤器:

在此处输入图像描述

And here I cant understand how can I write an expression saying:在这里我不明白我怎么能写一个表达:

If report "status" value = "Open" then show me the result where DueDate IS NULL, If report "Status" value = "Closed" then DueDate IS NOT NULL, And If report "Status" value = "Both" then show me all DueDates ( null and not null)如果报告“状态”值=“打开”然后显示结果,其中 DueDate 为 NULL,如果报告“状态”值 =“已关闭”则 DueDate 不为空,如果报告“状态”值 =“两者”则显示给我所有 DueDates(null 和 not null)

Another thing is I already have case statement in my query:另一件事是我的查询中已经有 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))
                        )

Is any way out of it in SSRS I can create parameter that accepts values Open, Closed and Both?在 SSRS 中有什么办法可以创建接受值 Open、Closed 和 Both 的参数?

Added test1添加了测试 1

在此处输入图像描述

Add a Filter in the tablix like this:在 tablix 中添加一个过滤器,如下所示:

在此处输入图像描述

In Expression use: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")

For Value use: Value用途:

="Include"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM