[英]Date column populating from CSV to table behaving differently using SSIS
I have CSV file 我有CSV文件
**date column**
06/04/1999
06/04/2000
.
.
.06/04/2017
I'm just loading this file from Csv file to Database table using SSIS 我只是使用SSIS将此文件从Csv文件加载到数据库表
Flat file source to OLEDB Destination
平面文件源到OLEDB目标
where date column is absolutely DT_STR and SQL Table date column is varchar(50) 其中date列绝对是DT_STR,SQL表日期列是varchar(50)
But it is behaving differently when I load sometimes it is populating like 但是当我加载时,它的行为会有所不同
**date column**
06/04/1999
06/04/2000
and some other times like 和其他一些时间一样
**date column**
1999-04-06
2000-04-06
I'm just trying to load the same what ever is there in Flat file but why it is giving "-" sometimes . 我只是想尝试加载平面文件中的相同内容,但为什么它有时会给出“ - ”。 Can any one please suggest me why it behaving differently each time .
任何人都可以建议我为什么每次都表现不同。 It doesn't have any conversions(like Derived Columns) in SSIS
它在SSIS中没有任何转换(如派生列)
You have to convert these values to DateTime then to String with desired format yyyy-MM-dd
using a ScriptComponent Transformation
您必须使用
ScriptComponent Transformation
将这些值转换为DateTime,然后转换为具有所需格式的字符串yyyy-MM-dd
Flat File connection manager
and an OLEDB Connection Manager
(Source and Destination) Flat File connection manager
和OLEDB Connection Manager
(源和目标) DataFlow Task
DataFlow Task
DataFlow Task
add a Flat File Source
, Script Component
, OLEDB Destination
DataFlow Task
添加Flat File Source
, Script Component
, OLEDB Destination
Source --> Script --> Destination
Source --> Script --> Destination
inDateColumn
) and add an Output Column (ex: OutDateColumn
) of String DT_STR
inDateColumn
)并添加字符串DT_STR
的输出列(例如: OutDateColumn
) In the Script Write The Following Code: (using Vb.net) 在脚本中编写以下代码:( 使用Vb.net)
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) If Not Row.inDateColumn_IsNull AndAlso _ Not String.IsNullOrEmpty(Row.inDateColumn.Trim) Then ' You can add more formats inside the following method Row.OutDateColumn = DateTime.ParseExact(Row.inDateColumn.Trim,New String(){"yyyy-MM-dd","dd/MM/yyyy"},New System.Globalization.CultureInfo("En-GB"), System.Globalization.DateTimeStyles.None).ToString("yyyy-MM-dd") Else Row.OutDateColumn_IsNull = True End If End Sub
Map OutDateColumn
to the destination column 将
OutDateColumn
到目标列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.