SQL 在 ssrs 表达式中使用“like”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9009825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:08:47  来源:igfitidea点击:

Using 'like' in ssrs expressions

sqlreporting-servicesexpressionreportbuilder3.0ssrs-expression

提问by blsub6

I'm trying to highlight a field when the value has the word 'deadline' in it. I'm trying to use the expression:

当值中包含“截止日期”一词时,我试图突出显示一个字段。我正在尝试使用表达式:

=IIf(Fields!Notes.Value like "%deadline%","Yellow","Transparent")

=IIf(Fields!Notes.Value like "%deadline%","Yellow","Transparent")

in the BackgroundColor property.

在 BackgroundColor 属性中。

It's not highlighting the field (not changing the background color). The 'Notes' field is a text datatype and I'm using Report Builder 3.0 if that makes a difference. What am I doing wrong?

它没有突出显示该字段(不更改背景颜色)。“注释”字段是一种文本数据类型,如果这有所不同,我将使用 Report Builder 3.0。我究竟做错了什么?

采纳答案by Oleg Dok

SSRS does NOTuse SQL syntax, but instead uses Visual Basic.

SSRS也不要使用SQL语法,而是使用Visual Basic中。

Use something like this:

使用这样的东西:

=IIf(Fields!Notes.Value.IndexOf("deadline") >= 0,"Yellow","Transparent")

Or .Contains instead of .IndexOf

或 .Contains 而不是 .IndexOf

=IIf(Fields!Notes.Value.ToLowerInvariant().Contains("deadline"),"Yellow","Transparent")

回答by devarc

It is like in access: not '%' but '*':

就像在访问中:不是 '%' 而是 '*':

=Fields!Notes.Value Like "*deadline*"

回答by JanBorup

"InStr" works for me:

“InStr”对我有用:

=IIF(InStr(Fields!Notes.Value,"deadline")>0, "Yellow", "Transparent") 

Remember that the compare value is case-sentive, so maybe use UCASE around:

请记住,比较值是区分大小写的,因此可以在周围使用 UCASE:

=IIF(InStr(UCASE(Fields!Notes.Value),"DEADLINE"))>0, "Yellow", "Transparent") 

回答by Etch

Why not use something like:

为什么不使用类似的东西:

Fields!Notes.Value.Contains("deadline")