简体   繁体   English

如何将 DB2 时间戳转换为 SQL Server datetime2?

[英]How to convert DB2 timestamp to SQL Server datetime2?

I am converting DB2 stored procedures to SQL Server.我正在将 DB2 存储过程转换为 SQL Server。 One of the common issue is that DB2 use a time date format timestamp very commonly, for which the closest SQL Server equivalent appears to be datetime2 .一个常见问题是 DB2 非常普遍地使用时间日期格式timestamp ,为此最接近的 SQL Server 等效项似乎是datetime2

What is an easy way to convert DB2 timestamp to datetime2 ?将 DB2 timestamp转换为datetime2的简单方法是什么?


I found this question but there was not any answer.我发现了这个问题,但没有任何答案。

DB2 timestamp is very similar to SQL Server datetime2 , except a hyphen and using periods instead of colons. DB2 timestamp与 SQL Server datetime2非常相似,除了一个连字符和使用句点而不是冒号。

You can use stuff() to change those characters and then convert() to datetime2 .您可以使用stuff()更改这些字符,然后convert()datetime2

Examples:例子:

declare @DB2_timpstamp varchar(30)
declare @SQL_datetime2 datetime2
set @DB2_timpstamp = '2019-02-02-11.22.33.456789'

set @SQL_datetime2 = try_convert(datetime2, stuff(stuff(stuff(@DB2_timpstamp, 17, 1, ':'), 14, 1, ':'), 11, 1, ' '))
select @SQL_datetime2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM