SSRS Contains or Like Expression

南楼画角 提交于 2019-12-09 15:59:23

问题


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'. 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.

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


回答1:


In String is your friend. 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. If it can't find the text, it returns 0, which you can use as false (or simply use >0 to represent 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". 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"

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:

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


来源:https://stackoverflow.com/questions/26937355/ssrs-contains-or-like-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!