简体   繁体   English

SSRS包含或喜欢表达

[英]SSRS Contains or Like Expression

I'm trying to create a calculated expression from a field in my dataset. 我正在尝试从我的数据集中的字段创建计算表达式。 I need to find everything that contain the word Exchange Traded from one field and in my new field have the words 'ETF 13F'. 我需要在一个字段中找到包含Exchange Traded一词的所有内容,并在我的新字段中找到“ETF 13F”字样。 If nothing matches then it would just be blank. 如果没有匹配,那么它就是空白。

I have tried the Like(" Exchange Traded ") and Contains (" Exchange Traded ") functions and when running the report I get a #error in my new field. 我尝试了Like(“ Exchange Traded ”)和Contains(“ Exchange Traded ”)函数,在运行报表时,我在新字段中得到#error。

Here's what I have tried... 这是我试过的......

=IIf(Fields!DESC2.Value.like("*Exchange Traded*"),"ETF_13F", false)

How do I write this wildcard expression and then replace with a different text in the new calculated field? 如何编写此通配符表达式,然后用新计算字段中的其他文本替换?

Thanks in advance 提前致谢

In String is your friend. 在String中是你的朋友。 You pass 2 arguments to the function InStr(), the first is the text to search and the second is the text you're searching for, it returns an Integer which represents the starting position of the text you're looking for in the text you told it to search. 您将2个参数传递给函数InStr(),第一个是要搜索的文本,第二个是您要搜索的文本,它返回一个Integer,它表示您在文本中查找的文本的起始位置你告诉它去搜索。 If it can't find the text, it returns 0, which you can use as false (or simply use >0 to represent true). 如果找不到文本,则返回0,可以将其用作false(或者只使用>0表示true)。 So... 所以...

=iif(InStr(Fields!DESC2.Value, "Exchange Traded") > 0, "ETF_13F", Nothing)

So that's looking for the string "Exchange Traded" in the field "DESC2". 因此,在“DESC2”字段中查找字符串“Exchange Traded”。 If it finds "Exchange Traded" then it returns a value that is more than 0, so all we do is say "If this value is more than 0, show ETF_13F, otherwise show nothing" 如果它找到“交易所交易”,那么它返回一个大于0的值,所以我们所做的就是“如果这个值大于0,则显示ETF_13F,否则不显示任何内容”

Hope that helps 希望有所帮助

EDIT: 编辑:

A few people have upvoted this, so as it's getting some visibility I'm going to update the answer to say there's a better way that someone clued me in to. 有些人对此有所支持,所以当它获得一些可见性时,我会更新答案,说有一个更好的方法,有人让我知道。 You can simply use .Contains() on String fields to perform the same inspection: 您可以在String字段上使用.Contains()来执行相同的检查:

=iif(Fields!DESC2.Value.Contains("Exchange Traded"), "ETF_13F", Nothing)

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

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