我在数据库中有一个存储为INT的列,我需要将列转换为TIME,但是省略了所有前导零。有没有办法可以做到这一点?
示例:
HH:mm(UI) HHmmssSSS(db)
11:08 1108ssSSS
04:36 **0**436ssSSS
00:12 **00**12ssSSS
00:05 **000**5ssSSS
答案 0 :(得分:0)
获得那些时间:
with CTE as
(
select otherfields, right('0000' + cast(IntField as varchar),4) as StrTime
from MyTable
)
select otherfields, CAST(STUFF(STUFF(STUFF(StrTime,3,0,':'),6,0,':'),9,0,'.') AS TIME)
from CTE