SSIS将字符转换为布尔值/位 [英] SSIS Converting a char to a boolean/bit

查看:38
本文介绍了SSIS将字符转换为布尔值/位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SSIS 包来加载数据;您可能还记得,当我尝试将它们作为位标志加载到 SQL Server 中时,数据文件中有一些标志作为 Y/N char(1).我将数据文件中的列指定为 String [DT_STR] 并且我有一个数据转换任务根据以下表达式将它们转换为布尔值(我收到了相同的转换错误,只是将它们指定为 DT_BOOL首先,尽管 SSIS 要求我说出它应该将哪些值视为布尔值):

I have an SSIS package to load data; as you may recall there are flags that are in data files as Y/N char(1) when I am trying to load them as bit flags into SQL Server. I am specifying the columns in the data file as String [DT_STR] and I have a data conversion task to convert them to booleans based on the following expression (I received the same conversion error just specifying them as DT_BOOL to begin with, despite SSIS asking me to say what values it should consider as boolean):

[ColumnName] == "Y" ? (DT_BOOL)1 : (DT_BOOL)0

运行包给出错误并告诉我转换规范的字符值无效由于潜在的数据丢失而无法转换该值在实际导入中到 SQL Server(通过 OLE DB 目标).

Running the package gives an error and tells me Invalid character value for cast specification and The value could not be converted because of a potential loss of data on the actual import to SQL Server (via an OLE DB Destination).

我在这里缺少什么才能正确转换?

What am I missing here to get it to properly convert?

推荐答案

我能够通过使用派生列解决它,而不是替换字符列,而是创建设置为 DT_BOOL像这样:

I was able to solve it by using a derived column and, instead of replacing the char columns, creating new columns set to type of DT_BOOL like so:

[Recycled] == "Y" ? True : False

这篇关于SSIS将字符转换为布尔值/位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆