在我的 SSIS 包中,我必须将值从 DateTime 转换为相应的 INTEGER 值。已提供以下示例。
关于如何转换这些有什么想法吗?
DATETIME INT
--------- ----
1/1/2009 39814
2/1/2009 39845
3/1/2009 39873
4/1/2009 39904
5/1/2009 39934
6/1/2009 39965
7/1/2009 39995
8/1/2009 40026
9/1/2009 40057
10/1/2009 40087
11/1/2009 40118
12/1/2009 40148
1/1/2010 40179
2/1/2010 40210
3/1/2010 40238
4/1/2010 40269
5/1/2010 40299
6/1/2010 40330
编辑:在最新版本的 SQL Server 中,转换为 float/int 不再有效。请改用以下内容:
select datediff(day, '1899-12-30T00:00:00', my_date_field)
from mytable
请注意,字符串日期应该位于明确的日期格式 http://www.karaszi.com/SQLServer/info_datetime.asp这样它就不会受到服务器区域设置的影响。
在旧版本的 SQL Server 中,您可以通过先转换为 float,然后再转换为 int,将 DateTime 转换为 Integer:
select cast(cast(my_date_field as float) as int)
from mytable
(注意:您不能直接转换为 int,因为如果您过了中午,MSSQL 会将值向上舍入!)
如果您的数据中有偏移,您显然可以从结果中添加或减去该偏移
您可以通过直接向后转换来向另一个方向进行转换:
select cast(my_integer_date as datetime)
from mytable
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)