gpt4 book ai didi

sql-server - SSIS 将时间戳列派生为日期和时间列

转载 作者:行者123 更新时间:2023-12-03 13:20:33 28 4
gpt4 key购买 nike

我在 varchar 中有这个 Timestr 28/12/2016 16:39:01
如何在 SSIS 中将列派生为日期和时间

想要的结果

日期 2016-12-28日期格式

时间 16:39:01时间格式

到目前为止,这是我在 SQL 中所拥有的

SELECT FORMAT(CAST((SUBSTRING(TimeStr,12,8)) AS DATETIME),'hh:mm:ss tt') AS Time

代码 enter image description here

结果 enter image description here

最佳答案

使用 SSIS 表达式,您可以尝试:

日期

(DT_DBDATE)(SUBSTRING(Timestr,7,4) + "-" + 
SUBSTRING(Timestr,4,2) + "-" + SUBSTRING(Timestr,1,2))

时间
(DT_DBTIME)(SUBSTRING(Timestr,12,8))

您的派生列设置应如下所示:

enter image description here

更新:DT_DBTIME 中避免毫秒
(DT_DBTIME2,0)(SUBSTRING(Timestr,12,8))

希望能帮助到你。

关于sql-server - SSIS 将时间戳列派生为日期和时间列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42657018/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com