如何将DB
中存储的内容转换为varchar(6)
(例如,实际上为HHmmss
格式的180000),我尝试以下但不会工作
select convert(time,'180000')
select cast('180000' as time)
答案 0 :(得分:4)
另一种方法
DECLARE @t VARCHAR(6)='180000';
SELECT CAST(STUFF(STUFF(@t,5,0,':'),3,0,':') AS time)
答案 1 :(得分:2)
试试这个:
select cast((substring('180000',0,3)+':'+substring('180000',3,2)+':'+substring('180000',5,2)) as time)
答案 2 :(得分:0)
select cast(format(180000, '00:00:00') as time), cast(format(131, '00:00:00') as time)