SSIS如何通过分隔符获取字符串的一部分 [英] SSIS How to get part of a string by separator

查看:186
本文介绍了SSIS如何通过分隔符获取字符串的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个SSIS表达式来获取分隔符之前的字符串的左边部分,然后将新的字符串放在一个新的列中。我检查了派生列,似乎没有这样的表达。 Substring只能返回固定长度的字符串部分。

I need an SSIS expression to get the left part of a string before the separator, and then put the new string in a new column. I checked in derived column, it seems no such expressions. "Substring" could only return string part with fixed length.

例如,使用分隔符字符串' - ':

For example, with separator string '-' :

Art-Reading                Should return Art
Art-Writing                Should return Art
Science-chemistry          Should return Science

PS
我知道这可以使用SUBSTRING_INDEX()在MySQL中完成,但是我正在寻找一个SSIS中的等效项,或至少在SQL Server

P.S. I knew this could be done in MySQL with SUBSTRING_INDEX(), but I'm looking for an equivalent in SSIS, or at least in SQL Server

推荐答案

当然可以:

只需配置您的派生列,如下所示:

just configure your derived columns like this:

这是表达你的生活更容易:

Here is the expression to make your life easier:

SUBSTRING(name,1,FINDSTRING(name,"-",1) - 1)

FYI,第二个1表示获取字符串 - 的第一次出现

FYI, the second "1" means to get the first occurrence of the string "-"

编辑:
表达式处理没有 - 的字符串

expression to deal with string without "-"

FINDSTRING(name,"-",1) != 0 ? (SUBSTRING(name,1,FINDSTRING(name,"-",1) - 1)) : name

这篇关于SSIS如何通过分隔符获取字符串的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆