案例测试是否存在子字符串并替换为空白
Case test if substring exist and replace with blank
我需要通过替换 INC, LTD, LTD. 来清理一组公司名称。 , INC. , others, 当它们是单独的单词时有一个空的 space (在单词之前有一个空格 space 即 Incoming INC)而不是公司名称的字母部分,即 INComing Money。
我试过的逻辑:
case
when FINDSTRING([Trade Name]," INC",1) > 0 then REPLACE([Trade Name]," INC","")
when FINDSTRING([Trade Name]," LTD",1) > 0 then REPLACE([Trade Name]," LTD","")
ELSE [Trade Name]
我在派生列中尝试了 SSIS 表达式:
FINDSTRING( [Trade Name] ," INC",1) ? REPLACE([Trade Name]," INC","") :
FINDSTRING([Trade Name]," LTD",1) ? REPLACE([Trade Name]," LTD",""):
收到的错误:
Error at Data Flow Task [Derived Column [1]]: Attempt to find the
input column named "A" failed with error code 0xC0010009. The input
column specified was not found in the input column collection.
在类似的情况下,使用脚本组件更容易清理此列,您可以简单地根据空格拆分列,然后重新连接不等于 INC
的部分,您可以使用以下方法可以做到这一点,或者您可以简单地使用 RegEx.Replace()
方法根据正则表达式替换值:
string value = "";
string[] parts = Row.TradeName.Split(' ');
foreach(string str in parts){
if(str != "INC"){
value += " " + str;
}
}
Row.outTradeName = value.TrimStart();
我需要通过替换 INC, LTD, LTD. 来清理一组公司名称。 , INC. , others, 当它们是单独的单词时有一个空的 space (在单词之前有一个空格 space 即 Incoming INC)而不是公司名称的字母部分,即 INComing Money。
我试过的逻辑:
case
when FINDSTRING([Trade Name]," INC",1) > 0 then REPLACE([Trade Name]," INC","")
when FINDSTRING([Trade Name]," LTD",1) > 0 then REPLACE([Trade Name]," LTD","")
ELSE [Trade Name]
我在派生列中尝试了 SSIS 表达式:
FINDSTRING( [Trade Name] ," INC",1) ? REPLACE([Trade Name]," INC","") :
FINDSTRING([Trade Name]," LTD",1) ? REPLACE([Trade Name]," LTD",""):
收到的错误:
Error at Data Flow Task [Derived Column [1]]: Attempt to find the input column named "A" failed with error code 0xC0010009. The input column specified was not found in the input column collection.
在类似的情况下,使用脚本组件更容易清理此列,您可以简单地根据空格拆分列,然后重新连接不等于 INC
的部分,您可以使用以下方法可以做到这一点,或者您可以简单地使用 RegEx.Replace()
方法根据正则表达式替换值:
string value = "";
string[] parts = Row.TradeName.Split(' ');
foreach(string str in parts){
if(str != "INC"){
value += " " + str;
}
}
Row.outTradeName = value.TrimStart();