Question

I am converting existing dts packages to ssis packages and I am running into issues with columns containing (what I thought was) packed data (comp-3 ?).

Edit: turns out the it wasn't packed data but binary zeros.

The source is in a SQL 2005 database. The column is datatype char(100) containing a comp-3 packed field. This originated from a COBOL program. Multiple values are stored in this one string. For example, substring(myfield,39,8) may contain a string representing a date. The collation is Latin1_General_BIN

The destination is a SQL 2008 database. The column datatype can be changed but right now it is a varchar(100). The collation is SQL_Latin1_General_CP1_CI_AS

The original dts worked correctly. In the destination database, substring(myfield,39,8) still returns a date string of "20140425". However, when I tried migrating it to ssis, this field is an empty string. substring(myfield,39,8) returns an empty string.

Here is the hex value of the data from the original datasource: 0x20202020202000000000000000000000000020202020202020202020202020202020202020203230313430343235202020202020202020202020202020202020202020202020200000000020202020202020202020202020202020202020202020202020

Here is the hex value after it is transferred to the destination: 0x202020202020

Something in the ssis seems to be converting the data before putting it in the destination table. How do I prevent this and copy exactly what is in the source database?

Was it helpful?

Solution

Thanks to help from @BillWoodger, I found that the issue was not actually with packed data but the data contained binary zeros. Some googling led me to this link which says that a binary 0 is handled differently between dts and ssis. In sql server 2005 ssis, a binary 0 is treated as an end of string character so everything after it is truncated.

My solution was to convert the original column to varbinary(100) in my source sql query and then add a script tranformation with vb.net to strip out the binary 0.

source query

select cast(mycolumn as varbinary(100)) as mybinary

vb.net tranformation

    Dim hexValue As Integer
    Dim finalStr As String
    finalStr = ""

    For i As Integer = 0 To Row.mybinary.Length - 1
        hexValue = Row.mybinary(i)
        If (hexValue = 0) Then
            finalStr = finalStr + " "
        Else
            finalStr = finalStr + System.Convert.ToChar(hexValue)
        End If
    Next

    Row.outColumn = finalStr

Here's another link that was helpful but didn't work for me b/c it eliminated some extra characters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top