SSIS How to get part of a string by separator usin

2019-02-19 00:54发布

I trying to write an SSIS expression to get the right part of a string before the separator and then put the new string in a new column. I have used Substring and Findstring in derived column but I am having trouble.

Company
Virgin Altantic - F30008 
Google - F38115

I need to retrieve F30008 and F38115.

I used the expression:

(DT_STR,65,1252)(FINDSTRING(Company,"- ",1) != 0 ? (SUBSTRING(Company,1,FINDSTRING(Company,"-",1) + 2)) : Company)

From this expression I got:

Company
Virgin Altantic - 
Google - 

标签: ssis
3条回答
Ridiculous、
2楼-- · 2019-02-19 01:11

Data:

|                    COMPANY |
|----------------------------|
|   Virgin Altantic - F30008 |
|            Google - F38115 |
| Google youtube - F38115169 |

Derived Column Code:

NewColumn1

SUBSTRING(Company,1,LEN(Company) - FINDSTRING(REVERSE(Company),"-",1) - 1)

NewColumn2

SUBSTRING(Company,LEN(Company) - FINDSTRING(REVERSE(Company),"-",1) + 3,FINDSTRING(REVERSE(Company),"-",1) - 2)

Result:

enter image description here

查看更多
beautiful°
3楼-- · 2019-02-19 01:21

Just use SSIS TOKEN with "-" delimiter and then use TRIM

查看更多
Viruses.
4楼-- · 2019-02-19 01:36

The problem you have is that you want the end of the string and your current code is giving you the beginning of the string.

The documentation for SUBSTRING specifies 3 parameters: expression, starting position and length. FINDSTRING is returning the position of the separator. What you are doing is specifying the start position at 1, the first character in your column.

Instead, make that the position of the separator, plus 2 spaces to account for the separator itself and the space. The length is going to be the LEN([Company]) - FINDSTRING([Company],"- ",1)

In all version of SSIS, we also have RIGHT which is a specialized version of SUBSTRING that you could have also used.

查看更多
登录 后发表回答