time(2)类型将毫秒保留两位,应用程序将time(2)类型转换为int存储到SQL Server后,以下两种方法均可将int转换为time(2):
--方法1
DECLARE @T int
SET @T = 10455836
SELECT DATEADD(hour, (@T / 1000000) % 100,
DATEADD(minute, (@T / 10000) % 100,
DATEADD(second, (@T / 100) % 100,
DATEADD(millisecond, (@T % 100) * 10, cast('00:00:00' AS time(2))))))
--方法2
SELECT CAST(STUFF(STUFF(STUFF(CAST(@T AS varchar),3,0,':'),6,0,':'),9,0,'.') AS time(2))