select stuff(stuff(时间,2,0,':'),5,0,':')
解决方案 »
- 关于sql2008数据表数据更新的问题
- 如何写去掉一个最大值,去掉一个最小值计算结果
- SQL SERVER 2005无法连接成功
- 200w的数据在mssql中搜索超时了...只是搜索标题而已,大家帮帮忙
- 开贴再问,直到解决问题,不信搞不定
- 如何卸载lumigent log explorer和删除lumigent数据库
- 以.PDF为后缀的文件怎么打开的
- 一个简单的T-SQL程序,新手自学,求高手赐教,帮我修改一下,最好是按照我的那种算法,让我明白我是错在哪,有什么想法改进的都可以教教我,谢谢了!
- 如何判断数据库中某个表已经存在?
- 问1个查询问题(结果需要其中某些列按随机排,某些列按顺序派)
- --------select convert(datetime,'2004-09-22 16:10:27.000',110)-----怎只取日期
- 请问怎样"返回"和"修改" 列 的属性。
结果: 12:13:21
估计楼主要分些情况处理吧,比方说:15:10:12是存为了151012
要是5:10:12 又是怎么存的呢?是051012,还是51012?
set @time='151012'
set @hour=substring(@time,1,2)
set @minute=substring(@time,3,2)
set @second=substring(@time,5,2)
exec xp_sprintf @out output,'%s:%s:%s',@hour,@minute,@second
print @out
TO lsxaa(小李铅笔刀)
估计楼主要分些情况处理吧,比方说:15:10:12是存为了151012
要是5:10:12 又是怎么存的呢?是051012,还是51012? 这个没考虑到,看楼主怎么存的了
set @time='151012'
set @hour=right(@time,2)
set @minute=left(right(@time,4),2)
set @second=case when len(@time)=5 then left(right(@time,5),1) else left(right(@time,6),2) end
set @out=@second+':'+@minute+':'+@hour
print @out
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15:10:12
set @time='51012'
set @hour=right(@time,2)
set @minute=left(right(@time,4),2)
set @second=case when len(@time)=5 then left(right(@time,5),1) else left(right(@time,6),2) end
set @out=@second+':'+@minute+':'+@hour
print @out
~~~~~~~~~~~~~~~~~~~~
5:10:12
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