这是时间转换问题:
7:30==>7+30*1.0/60
7:20==>7+20*1.0/60你要确认先格式化数据,秒你算不算?

解决方案 »

  1.   

    写了一个大概的,对于除不尽的,直接取小数后的第一位,你试试:
    select left(v,charindex(':',v)-1)+
           cast(cast(substring(v,charindex(':',v)+1,LEN(v))/60.0 as numeric(2,1)) as varchar) as '转换后的值'
    from 
    (
    select '7:30' v union all
    select '7:20' union all
    select '7:13'
    )t
    /*
    转换后的值
    70.5
    70.3
    70.2
    */
      

  2.   

    上面有点问题,修改一下:select left(v,charindex(':',v)-1)+
           cast(substring(v,charindex(':',v)+1,LEN(v))/60.0 as numeric(2,1)) as '转换后的值'
    from 
    (
    select '7:30' v union all
    select '7:20' union all
    select '7:13'
    )t
    /*
    转换后的值
    7.5
    7.3
    7.2
    */
      

  3.   

    这么简单的问题,楼主的用意只是要一个结果吗,方法有好多的,其实应该说得更详细一点。
    这个方法应该还行的吧:
    string str = Math.Round(TimeSpan.Parse("7:30").TotalHours, 1).ToString();
      

  4.   

    是SQL啊,那这样:
    declare @t time = '07:20'
    select CAST(DATEPART(hour,@t)+DATEPART(minute,@t)/60.0 as decimal(10,1))
      

  5.   


    create table wy
    (x varchar(10),y varchar(10))insert into wy(x)
     select '7:30' union all
     select '7:20'
    update wy
     set y=substring(x,1,charindex(':',x,1)-1)+'.'
          +rtrim(cast(substring(x,charindex(':',x,1)+1,10) as int)/6)
    select * from wy/*
    x          y
    ---------- ----------
    7:30       7.5
    7:20       7.3(2 row(s) affected)
    */