Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting BlobColumn to String in SSIS Script Component

Tags:

sql

ssis

How do I convert BlobColumn to String in SSIS Script Component.

E.G:

Source Column : OrganisationProviderID NVARCHAR(MAX)

Destination Column : OrganisationProviderID VARCHAR(20)

How can this be acheived in SSIS Script Component?

like image 866
Sreedhar Avatar asked Jan 05 '10 01:01

Sreedhar


2 Answers

Here is the function I use to convert BlobColumn to string in SSIS Script Components

string BlobColumnToString(BlobColumn blobColumn)
{
    if (blobColumn.IsNull)
        return string.Empty;

    var blobLength = Convert.ToInt32(blobColumn.Length);
    var blobData = blobColumn.GetBlobData(0, blobLength);
    var stringData = System.Text.Encoding.Unicode.GetString(blobData);

    return stringData;
}
like image 182
Dirk Brockhaus Avatar answered Oct 17 '22 04:10

Dirk Brockhaus


Why are you using the script component for this? Also, i'm not sure that a NVARCHAR(MAX) really qualifies as a BLOB column.

If you want to do it as part of a data flow task, on your Data Source, set the data access mode to 'SQL Command' then use the following command text:

select left(OrganisationProviderID,20) as OrganisationProviderID
from src

Then link this to your destination component.

like image 1
James Wiseman Avatar answered Oct 17 '22 04:10

James Wiseman