0

我有一列类型,nvarchar170948我想将它存储在时间类型列中

为此我写了

select @CurrentTimeValue=Convert(time, items, 108) from T

但它抛出错误

从字符串转换日期和/或时间时转换失败。

请建议正确的格式

4

3 回答 3

1

由于所有支持的CONVERT样式都与您的输入不匹配,因此您必须手动调整输入 - 如下所示:

DECLARE @input VARCHAR(10) = '170948'

DECLARE @modified VARCHAR(10)

SET @modified = SUBSTRING(@input, 1, 2) + ':' + SUBSTRING(@input, 3, 2) + ':' + RIGHT(@input, 2)

SELECT CAST(@modified AS TIME)
于 2013-10-22T06:44:39.590 回答
0
select cast(stuff(stuff('170948', 3,0,':'), 6,0,':') as time)
于 2013-10-22T06:57:26.820 回答
0

你也可以试试

select cast(stuff(stuff('170948', 5,0,':'), 3,0,':') as time)
于 2013-10-22T06:50:47.547 回答