views:

274

answers:

1

I am trying to remove part of a string from another string, for example:

declare @url varchar (20)
set @url = 'www.test.com~~34235645463544563554'

select @url, substring(@url,1,CHARINDEX('~~',@url)-1)

I am trying to remove '~~34235645463544563554'

I am use to using the built in tsql functions (as shown above) to do this but trying to do the same thing in a step in ssis as a "derived column transformation". Can someone suggest how I can do this and whether there is a easy way to quickly test this out in management studio? ie using the expression written in ssis to test for the expected result. I would prefer not to run the whole thing as it is a big package.

+1  A: 

In the end I used a script component:

Dim debugOn As Boolean
debugOn = False

If debugOn Then MsgBox(Row.trackingCode)
If Row.trackingCode <> "" Then
    ' find the delimiter location
    Dim endLocation As Integer
    If debugOn Then MsgBox("index of ~~ is " & Row.trackingCode.ToString().IndexOf("~~", 0))
    ' chk if we have ~~ in field, if not in field then -1 is returned
    If Row.trackingCode.ToString().IndexOf("~~", 0) > -1 Then
        ' if ~~ at the beginning ie no tracking code
        If Row.trackingCode.ToString().IndexOf("~~", 0) = 1 Then
            endLocation = Row.trackingCode.ToString().IndexOf("~~", 0)
        ElseIf Row.trackingCode.ToString().IndexOf("~~", 0) > 1 Then
            endLocation = Row.trackingCode.ToString().IndexOf("~~", 0) - 1
        End If
        If debugOn Then MsgBox("end of track code is " & endLocation)
        Row.trackingCode = Row.trackingCode.Substring(1, endLocation)
    End If
End If
Joe