SQL 在 SSIS 脚本组件中将 BlobColumn 转换为字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2003631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Converting BlobColumn to String in SSIS Script Component
提问by Sreedhar
How do I convert BlobColumnto Stringin SSIS Script Component.
我如何转换BlobColumn为Stringin SSIS Script Component.
E.G:
例如:
Source Column : OrganisationProviderID NVARCHAR(MAX)
Destination Column : OrganisationProviderID VARCHAR(20)
How can this be acheived in SSIS Script Component?
这如何实现SSIS Script Component?
采纳答案by James Wiseman
Why are you using the script component for this? Also, i'm not sure that a NVARCHAR(MAX) really qualifies as a BLOB column.
为什么要为此使用脚本组件?另外,我不确定 NVARCHAR(MAX) 是否真的符合 BLOB 列的条件。
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:
如果要将其作为数据流任务的一部分来执行,请在数据源上将数据访问模式设置为“SQL 命令”,然后使用以下命令文本:
select left(OrganisationProviderID,20) as OrganisationProviderID
from src
Then link this to your destination component.
然后将其链接到您的目标组件。
回答by Dirk Brockhaus
Here is the function I use to convert BlobColumn to string in SSIS Script Components
这是我用来在 SSIS 脚本组件中将 BlobColumn 转换为字符串的函数
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;
}

