数据库表t1,中的字段time(varchar(50))
time
00:10:00
01:00:20
03:15:12
要求时间和,得到:04:25:32
这里关键是我把时间格式的转换问题没弄明白,我sql是这样写的:
select sum(convert(smalldatetime ,[time]) from t1
请指解~~~~

解决方案 »

  1.   

    convert(smalldatetime ,[time])  會轉換成   1900-01-01 .......的格式
    select sum(convert(smalldatetime ,[time]) from t1
    若 超過了1年的時間的話直接去掉1900-01-01結果就有問題了
      

  2.   

    SELECT  convert(varchar(50), sum(convert(smalldatetime ,[time])),108) from t1
    試試看
      

  3.   

    sum or average aggregate 运算不能以 datetime 数据类型作为参数???
      

  4.   

    create table b (time varchar(8))
    insert into b select '00:10:00'
    union all select '01:00:20'
    union all select '03:15:12'select cast(h+m/60 as varchar(2))+':'+cast(m+s/60 as varchar(2))
    +':'+cast(s%60 as varchar(2)) as t 
    from 
    (
    select sum(cast (left(time,2) as int)) h
    ,sum(cast(substring(time,4,2) as int )) m
    ,sum(cast(right(time,2) as int )) s
    from b 
    ) a 
    ---------------
    总觉得这种数据处理好麻烦的
      

  5.   

    create table b (time varchar(8))
    insert into b select '00:10:00'
    union all select '01:00:20'
    union all select '03:15:12'declare @a datetime
    set @a = '19000101'
    select @a = @a + convert(datetime,time)
    from b
    select convert(varchar(8),@a,108)
    drop table b
            
    -------- 
    04:25:32(所影响的行数为 1 行)总觉得这种数据处理好麻烦的