简体   繁体   English

用于隐藏/显示文本框的 SSRS 表达式

[英]SSRS expression for hiding/showing text boxes

I have created an SSRS report.我创建了一个 SSRS 报告。

In this report I have created a dataset called: DataSet1.在这份报告中,我创建了一个名为:DataSet1 的数据集。 DataSet1 contains two columns: EntityId (integer) and Name (Varchar). DataSet1 包含两列:EntityId(整数)和 Name(Varchar)。 I would like to show a textbox if one of the values in the EntityId column is "27".如果 EntityId 列中的值之一是“27”,我想显示一个文本框。

So I want to write an expression that does this:所以我想写一个这样的表达式:

If one of the rows in DataSet1 has a EntityId value of 27, then show the textbox, else hide the textbox.如果 DataSet1 中的某一行的 EntityId 值为 27,则显示文本框,否则隐藏文本框。

From reading some other similar questions, I think counting the rows is probably the way to go.通过阅读其他一些类似的问题,我认为计算行数可能是要走的路。 So instead it might be something like:所以它可能是这样的:

Count the rows where DataSet1.EntityId = 27. If the number of rows is more than 0 then show the SSRS textbox, else hide the textbox.计算 DataSet1.EntityId = 27 的行数。如果行数大于 0,则显示 SSRS 文本框,否则隐藏文本框。

Any help with the expression would be much appreciated对表达式的任何帮助将不胜感激

You can do this easily with a simple expression.您可以使用简单的表达式轻松完成此操作。

Set the hidden property of the textbox to将文本框的hidden属性设置为

=SUM(IIF(Fields!EntityID.Value = 27,1,0), "DataSet1") = 0

All we are doing here is, starting from the inner expression...我们在这里所做的只是,从内心的表达开始......

  1. Check if EntityID = 27, if it does return 1 else return 0.检查EntityID = 27,如果确实返回 1,否则返回 0。
  2. Do this for each instance within the scope "DataSet1" (your entire dataset)"DataSet1"范围内的每个实例(您的整个数据集)执行此操作
  3. Sum the results总结结果
  4. Test if the result is zero测试结果是否为零

This will return True if the result is zero (no rows = 27) and therefore hide the textbox如果结果为零(无行 = 27),这将返回True并因此隐藏文本框

Note: the dataset name must be enclosed in quotes and is case sensitive.注意:数据集名称必须用引号引起来并且区分大小写。

In order to keep the expression simple, I would suggest to add the corresponding flag directly to the DataSet.为了保持表达式简单,我建议直接在DataSet中添加相应的标志。 Following an example:下面是一个例子:

DECLARE @t TABLE(
  EntityID int
 ,Title nvarchar(10)
)

INSERT INTO @t VALUES
(10, 'Test 1')
,(27, 'Test 2')
,(27, 'Test 3')
,(11, 'Test 4')
,(15, 'Test 5')
,(15, 'Test 6')
,(27, 'Test 7')

SELECT *, COUNT(CASE WHEN EntityID = 27 THEN 1 ELSE NULL END) OVER (ORDER BY (SELECT 1)) AS flag
  FROM @t

The column flag is 0 if no EntityID 27 is found and > 0 if this ID is found, so your expression would be something like if flag > 0 then... .如果未找到 EntityID 27,则列flag为 0,如果找到此 ID,则列flag为 > 0,因此您的表达式将类似于if flag > 0 then...

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

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