使用 SSIS 从 CSV 填充到 table 的日期列表现不同
Date column populating from CSV to table behaving differently using SSIS
我有 CSV 文件
**date column**
06/04/1999
06/04/2000
.
.
.06/04/2017
我正在使用 SSIS
将此文件从 Csv 文件加载到数据库 table
Flat file source to OLEDB Destination
其中日期列绝对是 DT_STR 并且 SQL Table 日期列是 varchar(50)
但是当我加载时它的行为有所不同,有时它正在填充
**date column**
06/04/1999
06/04/2000
还有其他一些时候
**date column**
1999-04-06
2000-04-06
我只是想加载平面文件中曾经存在的相同内容,但为什么它有时会给出“-”。
任何人都可以建议我为什么它每次都表现不同。
它在 SSIS
中没有任何转换(如派生列)
您必须使用 ScriptComponent Transformation
将这些值转换为日期时间,然后转换为具有所需格式 yyyy-MM-dd
的字符串
- 创建一个
Flat File connection manager
和一个 OLEDB Connection Manager
(源和目标)
- 添加一个
DataFlow Task
- 在
DataFlow Task
中添加一个Flat File Source
、Script Component
、OLEDB Destination
- 您的 DataFlow 应该看起来像
Source --> Script --> Destination
- 在脚本组件中,将时间列标记为输入(假设其名称为
inDateColumn
)并添加字符串 DT_STR
[=42 的输出列(例如:OutDateColumn
) =]
在脚本中写入以下代码:(使用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
将 OutDateColumn
映射到目标列
我有 CSV 文件
**date column**
06/04/1999
06/04/2000
.
.
.06/04/2017
我正在使用 SSIS
将此文件从 Csv 文件加载到数据库 tableFlat file source to OLEDB Destination
其中日期列绝对是 DT_STR 并且 SQL Table 日期列是 varchar(50)
但是当我加载时它的行为有所不同,有时它正在填充
**date column**
06/04/1999
06/04/2000
还有其他一些时候
**date column**
1999-04-06
2000-04-06
我只是想加载平面文件中曾经存在的相同内容,但为什么它有时会给出“-”。 任何人都可以建议我为什么它每次都表现不同。 它在 SSIS
中没有任何转换(如派生列)您必须使用 ScriptComponent Transformation
yyyy-MM-dd
的字符串
- 创建一个
Flat File connection manager
和一个OLEDB Connection Manager
(源和目标) - 添加一个
DataFlow Task
- 在
DataFlow Task
中添加一个Flat File Source
、Script Component
、OLEDB Destination
- 您的 DataFlow 应该看起来像
Source --> Script --> Destination
- 在脚本组件中,将时间列标记为输入(假设其名称为
inDateColumn
)并添加字符串DT_STR
[=42 的输出列(例如:OutDateColumn
) =] 在脚本中写入以下代码:(使用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
将
OutDateColumn
映射到目标列