Select 怎样格式化输出字符串
2个回答
展开全部
declare @time varchar(6),@newtime varchar(10) set @time='151012' set @newtime=case when len(@time)=6 then stuff(stuff(@time,3,0,':'),6,0,':') when len(@time)=5 then '0'+stuff(stuff(@time,2,0,':'),5,0,':') end print @newtime 或 declare @time varchar(6),@newtime varchar(10) set @time='51012' if len(@time)=6 begin set @newtime=stuff(stuff(@time,3,0,':'),6,0,':') end else if len(@time)=5 begin set @newtime='0'+stuff(stuff(@time,2,0,':'),5,0,':') end print @newtime 当@time='151012'时,结果为15:10:12 当@time='51012'时,结果为05:10:12
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询