SQL 是否可以在 SSIS 表达式中执行“LIKE”语句?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4739230/
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 08:57:57  来源:igfitidea点击:

Is it possible to perform a "LIKE" statement in a SSIS Expression?

sqlssissql-likecase-statementdataflowtask

提问by iamtheratio

I'm using a Derived Column Task to change column data using a CASE WHEN statement. However, I need to be able to say..

我正在使用派生列任务使用 CASE WHEN 语句更改列数据。但是,我需要能够说..

SQL CODE WOULD BE:

SQL 代码应该是:

CASE WHEN Column01 LIKE '%i%' THEN '0' ELSE '1' END


In SSIS Expression Language that would be:


在 SSIS 表达式语言中,这将是:

[Column01] == "i" ? "0" : "1"  (that's for equals i, not, LIKE %i%.


Is it possible to use a LIKE operator?


是否可以使用 LIKE 运算符?

采纳答案by Conspicuous Compiler

I believe you'll want to use the FINDSTRING function.

我相信您会想要使用 FINDSTRING 函数

FINDSTRING(character_expression, searchstring, occurrence)

...

FINDSTRING returns null if either character_expression or searchstring are null.

FINDSTRING(字符表达式,搜索字符串,出现次数)

...

如果 character_expression 或 searchstring 为 null,则 FINDSTRING 返回 null。

回答by Guilherme de Jesus Santos

I know it is an old question, but these days I found a good answer on web.

我知道这是一个老问题,但这些天我在网上找到了一个很好的答案。

If you want a expression for Containslike '%value%'you could use :

如果你想要一个包含的表达式,like '%value%'你可以使用:

FINDSTRING(col, "value", 1) > 0`

If you want a expression for Start withlike 'value%'you could use :

如果你想要一个Start with的表达式like 'value%'你可以使用:

FINDSTRING(col, "value", 1) == 1

And finally, if you want a expression for End withlike '%value'you could use :

最后,如果你想要一个End with的表达式like '%value'你可以使用:

REVERSE(LEFT(REVERSE(col), X))  == "value"

More details look this useful resource : Basic SSIS Equivalents to T-SQL's LIKE

更多细节看这个有用的资源:Basic SSIS Equivalents to T-SQL's LIKE