CAST vs ssis数据流隐式转换区别
CAST vs ssis data flow implicit conversion difference
我有一个 SSIS 包,它可以将一些数据从 Oracle 传输到 SQL 服务器。
在 Oracle 中,日期存储为浮点数,例如42824 == '2017-04-01'
- 使用数据库的应用程序写在 Delphi.
虽然select CAST(42824 as datetime)
在 Management Studio 中结果为 '2017-04-01 00:00:00.000'
,由程序包插入到 SQL 服务器 table 的日期时间列中的相同值 (42824) 显示 2017-03-30 00:00:00.000
。
注意:此数字的源数据类型为 DT_R8
,在数据转换组件中将类型更改为 DT_UI4
没有任何变化
谁能解释一下?
关于日期连续剧
存储在 Oracle (42824
) 中的值称为日期序列,它也用于 Microsoft Excel
。
Date Serial表示日期值与初始值之间的天数,即1899-12-30
您可以在以下位置阅读有关 Date Serials 的更多信息:
- Why is 1899-12-30 the zero date in Access / SQL Server instead of 12/31?
- convert Excel Date Serial Number to Regular Date
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天
有两种方法可以使用 SQL 服务器将其转换为日期:
select DATEADD(d,42824,'1899-12-30')
select CAST(36464 - 2 as SmallDateTime)
SSIS 隐式转换
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天
我有一个 SSIS 包,它可以将一些数据从 Oracle 传输到 SQL 服务器。
在 Oracle 中,日期存储为浮点数,例如42824 == '2017-04-01'
- 使用数据库的应用程序写在 Delphi.
虽然select CAST(42824 as datetime)
在 Management Studio 中结果为 '2017-04-01 00:00:00.000'
,由程序包插入到 SQL 服务器 table 的日期时间列中的相同值 (42824) 显示 2017-03-30 00:00:00.000
。
注意:此数字的源数据类型为 DT_R8
,在数据转换组件中将类型更改为 DT_UI4
没有任何变化
谁能解释一下?
关于日期连续剧
存储在 Oracle (42824
) 中的值称为日期序列,它也用于 Microsoft Excel
。
Date Serial表示日期值与初始值之间的天数,即1899-12-30
您可以在以下位置阅读有关 Date Serials 的更多信息:
- Why is 1899-12-30 the zero date in Access / SQL Server instead of 12/31?
- convert Excel Date Serial Number to Regular Date
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
有两种方法可以使用 SQL 服务器将其转换为日期:
select DATEADD(d,42824,'1899-12-30')
select CAST(36464 - 2 as SmallDateTime)
SSIS 隐式转换
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