gpt4 book ai didi

sql - CAST 与 ssis 数据流隐式转换差异

转载 作者:行者123 更新时间:2023-12-03 00:31:37 24 4
gpt4 key购买 nike

我有一个 SSIS 包,可以将一些数据从 Oracle 传输到 SQL Server。

在 Oracle 中,日期存储为浮点型,例如42824 == '2017-04-01' - 使用数据库的应用程序是用 Delphi 编写的。

选择CAST(42824作为日期时间)
在 Management Studio 结果 '2017-04-01 00:00:00.000' 中,由包插入 SQL Server 表中的日期时间列的相同值 (42824) 显示 2017-03-30 00:00:00.000

注意:此数字的源数据类型为 DT_R8,在数据转换组件中将类型更改为 DT_UI4 不会发生任何变化

谁能解释一下吗?

最佳答案

关于日期序列

存储在 Oracle 中的值 (42824) 称为日期序列,它也用于 Microsoft Excel 中。

Date Serial 表示日期值与初始值 1899-12-30 之间的天数

您可以在以下位置阅读有关日期连续剧的更多信息:

CAST方法

来自Microsoft Docs - CAST and CONVERT (Transact-SQL) :

Only supported when casting from character data to datetime or smalldatetime. When character data that represents only date or only time components is cast to the datetime or smalldatetime data types, the unspecified time component is set to 00:00:00.000, and the unspecified date component is set to 1900-01-01

因此,CAST 函数在转换日期时将值 1900-01-01 视为初始值。所以我们在使用它转换Date Serials时需要减去2天

有 2 种方法可以使用 SQL Server 将其转换为日期:

select DATEADD(d,42824,'1899-12-30')

select CAST(36464 - 2 as SmallDateTime)

SSIS 隐式转换

也按照这个Microsoft docs article

DBTYPE_DATE (This is an automation DATE type. It is internally represented as a double.. The whole part is the number of days since December 30, 1899 and the fractional part is the fraction of a day. This type has an accuracy of 1 second, so has an effective scale of 0.)

因此,SSIS 中的隐式转换在转换日期时将值 1899-12-30 视为初始值。所以用它转换Date Serials时不需要减去2天

关于sql - CAST 与 ssis 数据流隐式转换差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43635787/

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