sql-server - SSIS 包日期格式

标签 sql-server azure datetime ssis flat-file

我在 Azure 中有一个数据工厂,它有一个执行 SSIS 包的管道。此包中包含一个提取脚本,该脚本会将日期值从 2019-01-13 00:00:00 转换为 2019-01-13。此后,逻辑应用会选取 extract.txt 文件并将其发送到 sftp 以放入文件夹中。

正如您从 SSMS 中将 varchar 数据类型转换为日期的提取脚本中看到的那样(我在 Unix 中接收日期),对于到达日期,给出了以下值。

脚本

Script

数据查看器

Date Value

但是,当我打开 extract.txt 文件时,日期显示为:2019-01-13 00:00:00.0000000

谁能告诉我为什么他们认为这可能会发生?谢谢

最佳答案

当您将日期列映射到平面文件时,即使时间未出现在数据查看器或 ssms 中,它也会包含时间。

SSIS 解决方案

不要在源代码中使用 dateadd(),而是让列保持原样,在 SSIS 中使用具有以下表达式的派生列:

LEFT((DT_WSTR,50)DATEADD("s", [start], (DT_DATE)"1970-01-01",10)

输出

2019-01-13

基于Cast (SSIS Expression) official documentation :

When a string is cast to a DT_DATE, or vice versa, the locale of the transformation is used. However, the date is in the ISO format of YYYY-MM-DD, regardless of whether the locale preference uses the ISO format.

SQL Server 解决方案

使用以下 SQL 命令:

select convert(varchar(10), dateadd(S, [start], '1970-01-01'),120)

关于sql-server - SSIS 包日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54946830/

相关文章:

python - 值错误 : time data '24:00' does not match format '%H:%M'

sql - 选择与我交谈过的用户以及与他们的最后一条消息(例如 Whatsapp)

.net - SQL Server 2008 的免费架构导出?

azure - 使用 ReceiveMode.ReceiveAndDelete 处理在 Azure 暂存中运行的 ServiceBus 主题订阅者的技术

java - 互操作性 Azure 服务总线消息队列消息

c# - DateTime 天结束 24 :00 (midnight)

python - 带日期的 matplotlib 居中条形图

sql-server - 使用sql查询检索时如何对表中的月份进行排序?

混合了 LEFT 连接和 INNER 连接的 SQL 查询

reactjs - 使用 React 将 BlockBlob 上传到 Azure 存储