简体   繁体   English

我可以在 SSRS 表达式中使用 WHERE 子句吗?

[英]Can I use WHERE clause in an SSRS expression?

I saw the post on WHERE clause in SSRS expression .在 SSRS 表达式中看到了关于WHERE 子句的帖子。 I am also trying to do a where clause, but in a different way.我也试图做一个 where 子句,但以不同的方式。 I need to show ItemDesc when ItemId = 4. I set a parameter so that it will always equal 4 for this cell.当 ItemId = 4 时,我需要显示 ItemDesc。我设置了一个参数,使其始终等于该单元格的 4。 Now I just need the matching description field.现在我只需要匹配的描述字段。 I cannot hard code it because the description may change one day.我无法对其进行硬编码,因为描述可能有一天会改变。 Is there a way to associate the two fields?有没有办法将这两个字段关联起来?

=IIF(Parameters!ItemID_4.Value = 4, Fields!ItemDesc.Value,"")

I am converting from Crystal Reports to SSRS.我正在从 Crystal Reports 转换为 SSRS。 This first image is the output from CR.第一个图像是 CR 的输出。 I only need to show that ItemDesc in that top left cell.我只需要在左上角的单元格中显示 ItemDesc 。

在此处输入图片说明

This next image is from SSRS.下一张图片来自 SSRS。 It is not limiting the descriptions.它不限制描述。 It seems to be doing what my expression is saying.它似乎正在做我的表情所说的事情。 ItemID = 4, so display all ItemDesc values but the two fields are not associated right now. ItemID = 4,因此显示所有 ItemDesc 值,但现在这两个字段没有关联。 I need it to only show the matching value.我需要它只显示匹配的值。

在此处输入图片说明

Thank you for your help.感谢您的帮助。

I cannot hard code it because the description may change one day.我无法对其进行硬编码,因为描述可能有一天会改变。

You are hard coding the parameter anyway by trying to do it that way.无论如何,您通过尝试以这种方式对参数进行硬编码。 I don't think you need a parameter to achieve the result unless you are restricted from adjusting the dataset query.我不认为你需要一个参数来获得结果,除非你被限制调整数据集查询。

If you are using an embedded SQL query for your dataset, I would just put a filter in WHERE clause: WHERE ItemID = 4如果您对数据集使用嵌入式 SQL 查询,我只会在 WHERE 子句中放置一个过滤器: WHERE ItemID = 4

Another way if you can't adjust the query is to go to Report Data view > Right click on the dataset for your table, "Dataset Properties" > go to the "Filters" tab and add a filter with these settings: Expression = ItemID, Operator = "=", Value = "4" (or "@ItemID" if you want to keep your parameter).如果您无法调整查询,另一种方法是转到报表数据视图 > 右键单击​​表的数据集,“数据集属性”> 转到“过滤器”选项卡并使用以下设置添加过滤器:Expression = ItemID , Operator = "=", Value = "4" (或 "@ItemID" 如果你想保留你的参数)。

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

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